Skip to content

Instantly share code, notes, and snippets.

@ctfliblime
Created September 22, 2011 18:42
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 ctfliblime/1235618 to your computer and use it in GitHub Desktop.
Save ctfliblime/1235618 to your computer and use it in GitHub Desktop.
Why do these hashes have different contents?
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
sub return_void {
return;
}
sub return_undef {
return undef;
}
my %h1 = (a=>1, b=>return_void(), c=>3);
print Dumper \%h1;
my %h2 = (a=>1, b=>return_undef(), c=>3);
print Dumper \%h2;
__END__
Output is:
Odd number of elements in hash assignment at ./ptest.pl line 15.
$VAR1 = {
'a' => 1,
'3' => undef,
'b' => 'c'
};
$VAR1 = {
'c' => 3,
'a' => 1,
'b' => undef
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment