C.DeRykus wrote:
Basically, the one-liner reads the tab-delimited file line by line
(-n); autosplits fields the line into fields based on whitespace (-
a)
and populates @F with those fields. If the 2nd column $F[1] ,
hasn't been seen or differs with the previous line's 2nd col.,
then a new output file is opened with a name matching $F[1].
The entire current line $_ is then written to the file. Lastly, $F[0]
is saved to $old so when the next line is read, $F[0] can be
compared with $old to see if a new file should be opened.
Note on switches: -l * unnecessary so can be omitted
-F\t * could be added to split on
tab instead of whitespace
That won't work as the shell will interpolate away the backslash:
$ echo "one two three four" | perl -F\t -lane'print "$_: $F[$_]"
for 0 .. $#F'
0: one
1: wo
2: hree four
You have to quote it:
$ echo "one two three four" | perl -F'\t' -lane'print "$_:
$F[$_]" for 0 .. $#F'
0: one
1: two
2: three
3: four
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: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/