in reply to newbie questions on array access and control loops
Hope that might help.my @file = <FILE>; #all the contents of the file are # now in @file, one line per element my @toppart; my @bottompart; while(@file) { $_ = shift @file; push(@toppart, $_), next unless /PAGE: 2/; # this is reached after the match @bottompart = ($_, @file); last; } # at this point @toppart has all the lines from the file # that were above the first occurance of /Page: 2/ # @bottompart has the first matching line and the rest of # the file. # @file has the same as @bottompart without the matching # line. Obviously if you don't want the matching line # you don't need @bottompart.
jarich
|
|---|