in reply to $_ functions vs argument-using functions
Using $_ as the primary method of passing parameters to a function does not seem like good style to me. A common pattern amongst Perl's built-ins though is to pass a parameter, but use $_ when no parameter is passed. A la:
sub f3 { my $input = @_ ? shift : $_; return $input + 1; }
If you're using a vaguely recent version of Perl, the underscore prototype makes this simpler (and magically works with lexical $_):
sub f4 (_) { my $input = shift; return $input + 1; }
|
|---|