Skip to content

Instantly share code, notes, and snippets.

@jgrar
Created April 14, 2018 06:50
Show Gist options
  • Save jgrar/a418c85ee7e84860f540cb445734c28c to your computer and use it in GitHub Desktop.
Save jgrar/a418c85ee7e84860f540cb445734c28c to your computer and use it in GitHub Desktop.
Hash ref prototype issue passing between subs
#!/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