I have to admit up front, i'm not a terribly good perl programmer, and this little attempt at being "perlish" is stumping the hell out of me. 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'm trying to be what I consider to be "tricky" by using map and an anonymous subroutine, but i seem to be missing something entirely.

here's a sample set of data:

foo bar
   munch
bar
foo bar

which should end up with each word stored in a seperate array element. this is the code i've tried:

@temp = map { join '\n', split /\s/, $_ }, @file;

anyone feel like lending a helping hand? I could do it with a bunch of foreach loops and temp variables, but i have this itch to do it the hard way that really needs to be scratched. ;)

In reply to 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.