On Fri, 10 Sep 2004 12:44:51 -0400, David Greenberg
<[EMAIL PROTECTED]> wrote:
> >foreach( @ARGV ) {
> >       open IN, $_ or die "Couldn't open $_: $!\n";
> >       chomp( my @data = <IN> );
> >       close IN;
> >       foreach( @data ) { s/\s+//g; }
> >       foreach( 0..$#data ) { $results[$_] .= $data[$_]; }
> >}
> This is a little shorter and saves on iterations:
> for my $file (@ARGV) {
>      open IN, $file or die "Couldn't open $file: $!\n";
>      @results = map { my $line = $_; chomp $line; $line =~ s/\s+//g;
> $line } (<IN>);
>      close IN;
> }
> 
> -David
> 

Can you throw the 'chomp' in the assignment in that 'map' statement? 
Then, can you also throw in the substitution in the mix?  like this:
  @results = map{ my $line = chomp(  s/\s+//g ); } ( <IN> );

And if so, why not this:

  @results = map{ chomp( s/\s+//g ) } ( <IN> );

As long as we're playing Perl-Golf!!

I truly don't understand what 'map' is doing.  Can you explain it to
me?  I have tried to read perldoc -f map but it's a little weird and
hard to follow!

--Errin

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to