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

while: both syntaxes cant solve my problem

Thread Next
March 13, 2012 09:11
while: both syntaxes cant solve my problem
Message ID:
hi all,

I have a problem with the following structure:

while(<file>){$thevariable=$1 if (/variable1=(.*)/)};

Now I wanna be sure that variable1 was really set in the above
statement (it could have an old value from a previous embracing loop).
Then I tried:

while(<file>){if (/variable1=(.*)/)
     {$thevariable=$1} else {$thevariable="nonset"};

The problem is, the second while statement is resetting $thevariable
for every line in the file and not only for the matching one. The
 else {$thevariable="notset"} option should be actually only run if
we reach the end without matching. But both while structures above
aren't solving my problem.

Thanx in advance for any help!

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About