public
Created

annon { $label => ...} with out assignment is seen as a list?

  • Download Gist
annon_hash_eq_list.t
Perl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
#!/usr/bin/env perl
use strict;
use warnings;
use Test::Most qw{no_plan};
 
my $data = [{ label => {key => 'value'}}];
 
eq_or_diff
[ map{ my $hash = $_;
my $x =
{ map { my $label = $_;
$label => $hash->{$label}
} keys %$hash
}
} @$data
],
[ map{ my $hash = $_;
#my $x =
{ map { my $label = $_;
$label => $hash->{$label}
} keys %$hash
}
} @$data
],
q| annon { $label => ...} with out assignment is seen as a list? |;
 
__END__
not ok 1 - annon { $label => ...} with out assignment is seen as a list?
# Failed test ' annon { $label => ...} with out assignment is seen as a list? '
# at data_eq.t line 17.
# +----+----------------------+----+--------------------+
# | Elt|Got | Elt|Expected |
# +----+----------------------+----+--------------------+
# | 0|[ | 0|[ |
# | | * 1| 'label', *
# | 1| { | 2| { |
# * 2| label => { * 3| key => 'value' *
# * 3| key => 'value' * | |
# * 4| } * | |
# | 5| } | 4| } |
# | 6|] | 5|] |
# +----+----------------------+----+--------------------+
1..1
# Looks like you failed 1 test of 1.

I think it's interpreting the braces as a bare block.

You can stick "scalar" or + in front of the { to force Perl to interpret it as a hash ref.

Ahhhh. Bare block that makes sence.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.