When passing to subroutines, the convention is; if there are more than 3-4 things you are passing you should probably be using an anonymous hash, otherwise you can just pass the value directly.
eg:
-
sub passing_things {
-
my $thing = shift;
-
do stuff with thing passed...
-
}
-
# Then later...
-
passing_things($variable);
-
-
The value in $variable will be passed to the subroutine.
However if you find you are sending
a lot of things you can just use an anonymous hash:
-
sub passing_more_things {
-
my $things = shift;
-
do many things with lots of stuff...
-
}
-
# then later...
-
passing_more_things({ one => $var, two => $var2, three => $var3, four => $var4});
-
-
# If you want to you can pass different kinds of things explicitly:
-
passing_more_things($variable, { one => $var, two => $var2}, @array);
-
-
In that case all that stuff will be "flattened" into an anonymous array "@_" inside the sub:
-
sub big_passing {
-
my @all_the_stuff = @_;
-
}
-
# Then later
-
my $var = 'hello';
-
my @array = ('perl', 'is', 'very', 'flexible');
-
-
big_passing($var, @array, { kelicula => 'loves', all => 'things_perl'});
the contents of @all_the_stuff would be:
hello, perl, is, very, flexible, kelicula, loves, all, things_perl.
Get it?