Created
April 14, 2018 06:50
-
-
Save jgrar/a418c85ee7e84860f540cb445734c28c to your computer and use it in GitHub Desktop.
Hash ref prototype issue passing between subs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use utf8; | |
use diagnostics; | |
use Data::Dumper; | |
sub takeshash (\%) { | |
my ($ref) = @_; | |
takesscalar($ref); | |
#takesscalar $ref; # cannot call on unblessed reference | |
takeshashref($ref); | |
#takeshashref(%{$ref}); # incorrect output | |
#takeshashref %{$ref}; # bareword not allowed | |
} | |
sub takeshashref (\%) { | |
my ($ref) = @_; | |
print "takeshashref\n"; | |
print Dumper([$ref]); | |
} | |
sub takesscalar ($) { | |
my ($ref) = @_; | |
print "takescalar\n"; | |
print Dumper([$ref]); | |
} | |
my %hash = ( | |
foo => 'bar', | |
baz => 'zorp', | |
); | |
takeshash(%hash); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment