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...)

In reply to Re: using map and anonymous subroutines by flyingmoose
in thread using map and anonymous subroutines by ritontor

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.