On 3/12/12 Mon Mar 12, 2012 10:17 AM, "oxy" <oxyo...@googlemail.com> scribbled:
> 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? The first while loop reads the entire file and exits when the <file> operation returns undef. The second while loop attempts to read the same file, the <file> operation returns undef on its first execution, and the statements within the second while loop are never executed. You may want to combine the two while loops or use some other logic to get what you want. -- Jim Gibson -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/