Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: [Solved] How does map work?

by Bloodnok (Vicar)
on Oct 28, 2013 at 11:48 UTC ( [id://1059962]=note: print w/replies, xml ) Need Help??


in reply to [Solved] How does map work?

Hmm,

Altho' perfectly correct, methinx that the simple for loop construct you use is more normally written as

push @ret, $coderef->() for @params;

In fact, simpler still would be use the incoming arg list directly and to use parens for the non-core call to foo (as per PBP) ...

#!/usr/bin/env perl use 5.010; use strict; use warnings; sub foo(&@) { my $coderef = shift; my @ret; push @ret, $coderef->() for @_; return @ret; } my @a = ( "1", "2", "3", "4", ); my @b = foo( sub { $_ ** 2 }, @a);
Yet another product of an idle moment ...

A user level that continues to overstate my experience :-))

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-03-28 13:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found