On May 15, 12:28 pm, mike.j...@cox.net (Mike McClain) wrote:
> In reading in a file of space separated columns of numbers
> and stuffing them into an array, I used:
>     while( my $line = <$FH> )
>     {   my @arr = split /\s+/, $line;
>         push @primes_array, @arr;
>     }
>
> but kept getting empty array entries until I switched to:
>     while( <$FH> )
>     {   my @arr = split;
>         push @primes_array, @arr;
>     }
>
> perldoc -f split says:
> If EXPR is omitted, splits the $_ string.  
> If PATTERN is also omitted, splits on whitespace
> (after skipping any leading whitespace).
>
> My question is what RE do I need to pass to split to get
> the same return from    split /$RE/, $line;
> as I get from the split against $_.
>
> Thanks,
> Mike
> --
> Satisfied user of Linux since 1997.
> O< ascii ribbon campaign - stop html mail -www.asciiribbon.org

Hello Mike

Boy, you were close.  ;-)

Also from documentation on split:

As a special case, specifying a PATTERN of space (' ' ) will split on
white space just as split with no arguments does. Thus, split(' ') can
be used to emulate awk's default behavior, whereas split(/ /) will
give you as many initial null fields (empty string) as there are
leading spaces. A split on /\s+/ is like a split(' ') except that any
leading whitespace produces a null first field. A split with no
arguments really does a split(' ', $_) internally.

Chris


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to