in reply to 'rewinding' file to get value from previous line in file?
This should get you where you want to go:
#!/usr/bin/perl use strict; my @Z; my $last_stop; while (<DATA>) { chomp; my @token = split ' '; if ( $token[0] eq 'Z' ) { if ($token[1] == $last_stop + 1) { $Z[-1]->[1] = $token[2]; } else { push @Z, [ @token[1,2] ]; } $last_stop = $token[2]; } } print Dumper(\@Z); __DATA__ Z 5 89 Z 92 102 Z 103 123 Z 126 150
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: 'rewinding' file to get value from previous line in file?
by ikegami (Patriarch) on Dec 07, 2006 at 19:00 UTC | |
|