in reply to Looking Backward While counting
I make the follwing assumptions:
- it is "##closeFlag## (without blank)
- your input is stored in a file called "in.txt"
- the input file is small enough to fit into memory
use strict; # first slurp the file my $content = do { local $/; open my $fh, "<", "in.txt" or die $!; <$fh> }; # then split it into chunks my @chunks = $content =~ /##Flag##(.*?)##CloseFlag##/sg; # now analyze the chunks for my $chunk (@chunks) { my ($first, $last) = $chunk =~ /T:(\d+).*?(\d+)\D*$/s; # count number of newlines my $newlines = $chunk =~ tr/\n/\n/; print "first-last: ", $first - $last, "# of lines: ", $newlines-1, +"\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Looking Backward While counting
by johngg (Canon) on Oct 15, 2010 at 23:21 UTC |