Skip to content

Instantly share code, notes, and snippets.

@notbenh
Created September 29, 2011 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notbenh/1250159 to your computer and use it in GitHub Desktop.
Save notbenh/1250159 to your computer and use it in GitHub Desktop.
annon { $label => ...} with out assignment is seen as a list?
#!/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.
@schwern
Copy link

schwern commented Sep 29, 2011

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

@schwern
Copy link

schwern commented Sep 29, 2011

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

@notbenh
Copy link
Author

notbenh commented Sep 29, 2011

Ahhhh. Bare block that makes sence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment