DS has asked for the wisdom of the Perl Monks concerning the following question:
where the first number in each line indcating the line number. in my second file I have only line numbers that been changed , somthing like thisdata.txt hello.pl~45~warning~454~null pointer hello.pl~43~warning~454~memory hello.pl~4532~warning~454~badpointer hello.pl~22~warning~454~null pointer hello.pl~88~warning~454~null pointer
where 22-33 indicating that line 22 to 33 have changed. so what I need to do is reading from the lineChanged.txt file each line and see if they appear in data.txt or they are in the range , if it does then I want to print that line from the data.txt and send it to a an output file , so in my example , my output will belineChanged.txt 22-33 90 42-44 100
since they appear in both files I am doing somthing like this right now but it is not doing the workhello.pl~43~warning~454~memory hello.pl~22~warning~454~null pointer
can someone tell me an easir way or tell me what is it wrong I am doing .. thanks for helpwhile (<CHANGES>) { chomp; # split the line from the spaces # $file is file name like hello.pl $info = $_; is it a range or a single line? if ($info =~ /(\d+)-(\d+)/) { $changes{$file} .= " ".join(" ",($1 .. $2))." "; } else { $changes{$file} .= " $info "; } if (defined $changes{$file}) { # was it a range? if (defined $changes{$file}->[1]) { # skip if this $line is not in this range next unless ($line gt $changes{$fill}->[0] and $line lt $change +s{$file}->[1]); } else { # skip if this $line is not equal to this single line number next unless $line eq $changes{$file}->[0]; } # if we are here, then this is a match. so print it. print "############ Here ################\n"; # print "$_\n"; #print "############ Here ################\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regex with comparing
by seattlejohn (Deacon) on Jul 19, 2002 at 05:24 UTC | |
|
Re: regex with comparing
by tadman (Prior) on Jul 19, 2002 at 05:18 UTC |