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

Re: using map and anonymous subroutines

by flyingmoose (Priest)
on Apr 20, 2004 at 13:36 UTC ( [id://346623]=note: print w/replies, xml ) Need Help??


in reply to using map and anonymous subroutines

I love my map and anonymous subs! That's about the most fun part of Perl for me... :) Go go functional programming!

Essentially, i'm trying to take the values in an array, split them on white space, append a newline, and then store it all in another array

I'd do it like this:

my @file = ("eddie van halen", "david lee roth", "alex van halen", "mi +chael anthony"); my @stuff = map { "$_\n"; } map { split /\s+/, $_; } @file; print @stuff;

edit: doh! dragon beat me to it (that's what I get for not reading responses first), but ah well at least I arrived at the exact same solution (I'm just overly explicit -- call it paranoia) so I guess it proves we are likely equally insane or something like that :)

If you want to remove things from that group, you use grep
Not just that, but for those that don't know grep, it's also very nice for searching and counting! Essentially you are counting by removing all of the "non-hits" and then checking the scalar value of the array result, aka cardinality of the set. R0XX0R! (err, sorry, 1337 speak outbreak...)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-04-25 09:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found