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 $_.

perldoc -f 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 null
       initial fields 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.

So you want:

split ' ', $line;



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to