Skip to content

Instantly share code, notes, and snippets.

@swelljoe
Last active July 8, 2017 00:17
Show Gist options
  • Save swelljoe/133c6e6cf3928f6e419bb3f58e27adc7 to your computer and use it in GitHub Desktop.
Save swelljoe/133c6e6cf3928f6e419bb3f58e27adc7 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
my $extrakey = "doot";
my $extraval = "toot";
my %hash = (
name => 'Joe',
age => 'Grumpy',
);
sub myFunction {
my %hash = @_;
say $hash{name};
say $hash{doot};
say $hash{age};
}
myFunction($extrakey, $extraval, %hash);
# This prints:
# Joe
# toot
# Grumpy
@swelljoe
Copy link
Author

swelljoe commented Jul 7, 2017

Everything gets flattened as it comes into the function.

Refs are the way to avoid that flattening (because a ref just points to data, it isn't the data so there's nothing to flatten), if you need to pass in complex data structures.

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