pldanutz has asked for the wisdom of the Perl Monks concerning the following question:
By $_-using functions, I mean functions that take their argument from the implicit variable $_, instead of relying on "actual" arguments that a sub receives in @_
Some second-order functions (e.g. map, as I learned in map sub to list?) prefer $_-using functions, instead of functions that use their @_ arguments:
Is one style preferred over the other in general? How can I convert between them?
P.S. How do I even search for stuff like this? I'm sure others must have asked this before.sub f1 ($) { shift(@_) + 1 } sub f2 { $_ + 1 } map (f1($), (10, 20)) # convert f1 to $_-style my $x = f1 (10) # call f1 with an arg # my $y = f2 (10) # won't work, how to use f2??
|
---|
Back to
Seekers of Perl Wisdom