develooper Front page | perl.beginners | Postings from March 2012

while: one supresses the other?

Thread Next
From:
oxy
Date:
March 12, 2012 10:17
Subject:
while: one supresses the other?
Message ID:
CAO4+0dGGp=QCqsZZJ+=PN4WTPw5C6D-ZucpxWfy4_0mSMURr9Q@mail.gmail.com
Hi,

i have the following file content: numbers = one two three four

I run the code:
================= begin code ==================
#!/usr/bin/perl -w
$AG2 = non;
$AG3 = non;
open (file , "<inpfile.txt");

while(<file>){if (/(.*)\s*=\s*.*three.*/) {$AG3 = $1} else {$AG3 ='not
found 3'};};
while(<file>){if (/(.*)\s*=\s*.*three.*/) {$AG2 = $1} else {$AG2 ='not
found 2'};};

print "AG2 is $AG2----------------------AG3 is $AG3 -------------\n";

================ end code ========================

Now, only the first while command will be read. The second is ignored.
Change the order of the lines and the same happens.
??????? Any idea?
tx

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About