And you can write your own function that takes an implicit $_ using the (_) prototype.
My favourite use for $_ is when defining a function that accepts a coderef. Example
# This is a fairly useless function which is basically # just a copy of grep which enforces numeric context # on the list items... # sub filter_nums (&@) { my $coderef = shift; return grep { $coderef->() } map { 0 + $_ } @_ } my @even = filter_nums { not($_ % 2) } qw(1 2 3 4 potato);
In reply to Re^2: the $_ Special Variable
by tobyink
in thread the $_ Special Variable
by MiriamH
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |