in reply to Variable number of words/fields in a line/record
See also splice split join perlop.while (<IN>) # Note: using $_ instead { my (@two, @rest); chomp; @rest = split; # Note that this is the same as (split ' ', $_) . # ' ' is generally a better choice than /\s/ for sp +litting on # whitespace. If you need to count multiple spaces + as # multiple fields, use /\s/ or / / instead. @two = splice @rest, 0, 2; print join(' ',@two,undef),join('|',@rest),"\n"; # The undef is to + put another space in before @rest }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Variable number of words/fields in a line/record
by premchai21 (Curate) on Jun 16, 2001 at 08:08 UTC |