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; }

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: How does map work?
by three18ti (Monk) on Oct 26, 2013 at 20:38 UTC
    Awesome! Thanks! using for instead of while definitely solved my problem.