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

while: both syntaxes cant solve my problem

Thread Next
From:
oxy
Date:
March 13, 2012 09:11
Subject:
while: both syntaxes cant solve my problem
Message ID:
CAO4+0dHLUWOAQwsDXt-p-m9+1MBhXAL=4SD-Fbg-b7CT+=jrKA@mail.gmail.com
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


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