Yes, that does work. What does not work so easily is when you want to pass the values of a hash to the function in such a way that it can write them. Eg. this works, the function can change the value in the hash:
my %d = ("foo", "bar"); sub fs { $_[0] = "quux"; } fs(values %d); prin +t join(" ", %d), $/; # OUTPUT: foo quux
But this does not work:
my %d = ("foo", "bar"); sub fi { ${$_[0]}[0] = "quux"; } fi([values %d +]); print join(" ", %d), $/; # OUTPUT: foo bar
Instead you could do
my %d = ("foo", "bar"); sub fi { ${$_[0]}[0] = "quux"; } sub capture { + \@_ } fi(capture(values %d)); print join(" ", %d), $/; # OUTPUT: foo quux
But that's probably all irrelevant to your question.
In reply to Re: passing array ref without variable
by ambrus
in thread passing array ref without variable
by vit
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |