in reply to Re: the $_ Special Variable
in thread the $_ Special Variable
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);
|
|---|