in reply to [Solved] How does map work?
But that produces the error "Use of uninitialized value $_ in exponentiation (**) at coderef.pl line 19."
The problem is your use of $_.
You pass it to the coderef as an argument, but you never set it!
And within the coderef -- ie. subroutine -- the first argument passed is aliased to $_[0] as with all subroutines.
To be able to use $_ within the coderef, you need to set it before calling the block. Try:
sub foo(&@) { my $coderef = shift; my @ret; for( @_ ) { ## let the for loop do the localisation and aliasing push @ret, $coderef->(); ## No arg } return @ret; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How does map work?
by three18ti (Monk) on Oct 26, 2013 at 20:38 UTC |