belden has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use strict; use warnings; while(<DATA>) { my $len = length($_); chomp; push ( my @three, $_ ); # Grab next two lines in file my $c; CALL: while (<DATA>) { chomp; last CALL if $c++ == 2; push ( @three, $_ ); } # Do stuff to process @three print $_,"\t" for ( @three ); print("\n"); # Rewind or stop eof(DATA) ? last : seek(DATA, -($len*3), 1); } __DATA__ 1 2 3 4 5 6
Output:
1 2 3
2 3 4
3 4 5
Aside from adding a blank line to the end of my data
(which is imho a silly workaround for a small problem), how
do I get it to print the trailing triplet:
4 5 6
Thanks -
blyman
setenv EXINIT 'set noai ts=2'
Replies are listed 'Best First'. | |
---|---|
Re: Grabbing lines three-by-three from a file
by mortis (Pilgrim) on Dec 11, 2001 at 00:00 UTC | |
Re: Grabbing lines three-by-three from a file
by tadman (Prior) on Dec 11, 2001 at 00:42 UTC | |
by runrig (Abbot) on Dec 11, 2001 at 00:59 UTC | |
by tadman (Prior) on Dec 11, 2001 at 02:21 UTC | |
Re: Grabbing lines three-by-three from a file
by merlyn (Sage) on Dec 11, 2001 at 02:10 UTC | |
Re: Grabbing lines three-by-three from a file
by runrig (Abbot) on Dec 11, 2001 at 00:36 UTC | |
Re: Grabbing lines three-by-three from a file
by belden (Friar) on Dec 11, 2001 at 03:29 UTC | |
Re: Grabbing lines three-by-three from a file
by joealba (Hermit) on Dec 11, 2001 at 00:11 UTC |