[pm-h] when is a anonymous hash reference is not...

Michael R. Davis mrdvt92 at yahoo.com
Mon Apr 20 06:34:05 PDT 2015


Perl Folks,Here's an interesting Perl-ism that bit me yesterday.  I've been starting to drop my sub "return" but I'm going back to being explicit as the performance hit has been fixed in later Perls and it just doesn't pay for itself in debugging.  Moral of the story: be explicit. I hope someone finds this helpful.Mike  perl -e '
use strict;
use warnings;
use Data::Dumper qw{Dumper};
our @list=(a=>1, b=>2);
sub a {{a=>1, b=>2}};   #{} is anon hash ref
sub b {[@list]};        #{} is anon array ref
sub c {{@list}};        #{} is block returns list
sub d {return {@list}}; #{} is anon hash refprint Dumper({a=>a(), b=>b(), c=>c(), d=>d()});
'
Odd number of elements in anonymous hash at -e line 11.
$VAR1 = {
          '1' => 'b',
          'c' => 'a',
          'a' => {
                   'a' => 1,
                   'b' => 2
                 },
          'b' => [
                   'a',
                   1,
                   'b',
                   2
                 ],
          'HASH(0x10b8b70)' => undef,
          '2' => 'd'
        };
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/houston/attachments/20150420/b399ac4c/attachment.html>


More information about the Houston mailing list