Re: help regarding Comparision
- From: yitzle@xxxxxxxxxxxxxxxxxxxxx (Yitzle)
- Date: Wed, 26 Sep 2007 14:44:03 -0400
Input:
--- START ---
abc
def
string1
das
dsfa
string2
dasf
string1
string2
dfsdsf
--- END ---
Code:
--- START ---
#!/usr/bin/perl
use warnings;
use strict;
die "Wrong usage\n" unless (defined $ARGV[0] and -f $ARGV[0]);
open my $FH, "< $ARGV[0]" or die "Can't open file\n";
my $string1 = 0; # Track if the first string occurred last line
while (<$FH>) {
print "$_"; # Echo the line
if ($string1) { # We hit string1 last line...
if (/string2/) { # ...and string2 this line
print "Found the double string!\n";
}
}
$string1 = (/string1/);
}
close $FH;
--- END ---
Output:
--- START ---
abc
def
string1
das
dsfa
string2
dasf
string1
string2
Found the double string!
dfsdsf
--- END ---
HTH
.
- Follow-Ups:
- Re: help regarding Comparision
- From: Dr.Ruud
- Re: help regarding Comparision
- References:
- help regarding Comparision
- From: Raaki
- help regarding Comparision
- Prev by Date: Re: help regarding Comparision of two lines
- Next by Date: Re: Displaying a Link on A Web PAge with image/png header.
- Previous by thread: help regarding Comparision
- Next by thread: Re: help regarding Comparision
- Index(es):