in reply to using map and anonymous subroutines

Basically, I think dragonchild has it right. The "trick" is to build the map expression piece by piece. I'm unclear about the use of the array @file. If you are reading data from a file, or line by line in some way, and loading it into @file, you might consider processing the file directly as
use strict; use warnings; my @tmp01 = (); push @tmp01, map{ $_."\n"} split " " while <DATA>; exit; __DATA__ foo bar munch bar foo bar
The split " " construct ensures that the function splits on whitespace, /\s+\, after skipping any leading whitespace although when I tried split with and without the " " argument, it worked correctly both ways.

Replies are listed 'Best First'.
Re: Re: using map and anonymous subroutines
by linux454 (Pilgrim) on Apr 20, 2004 at 14:21 UTC
    The following variant of the above is how I would write it.
    # SNIP # my @temp = map { $_ . "\n" } map { split(/\s+/) } <DATA> # SNIP #
    It is functionally the same, I just find it easier to read, but then my views of readability don't always align with others.