Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: How does map work?

by LanX (Saint)
on Oct 26, 2013 at 20:21 UTC ( [id://1059840]=note: print w/replies, xml ) Need Help??


in reply to [Solved] How does map work?

$_ does not belong to @_, you have to set this global variable explicitly and not pass it.

Eg by changing while to for (another bug in your code btw is to think that while automatically sets $_)

Im pretty sure HOP already shows how to emulate map! Sorry no code am typing on my mobile... :-)

Cheers Rolf

( addicted to the Perl Programming Language)

Replies are listed 'Best First'.
Re^2: How does map work?
by three18ti (Monk) on Oct 26, 2013 at 20:36 UTC

    thanks for the assist. Indeed my use of while was incorrect

    Indeed HOP does doe a version of map that takes an iterator, and I'm sure it will just take plugging away at HOP some more, it starts to make sense after a few read throughs...

      Hmm seems like HOP doesn't show how to reimplement plain map.

      But as a side note, perlsub has an example for grep :

      And here’s a reimplementation of the Perl "grep" operator: sub mygrep (&@) { my $code = shift; my @result; foreach $_ (@_) { push(@result, $_) if &$code; } @result; }

      HTH!

      Cheers Rolf

      ( addicted to the Perl Programming Language)

      There is one instance where while sets $_ (or at the very least has the appearance to do so), and that's in the special while( <$filehandle> ) {...} construction (or ... while <$filehandle> for that matter, I believe).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1059840]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-18 01:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found