in reply to Re: problem with variables
in thread problem with variables

Just to elaborate a little further, $1 holds the value of the first capturing parens in the last successful pattern match. It's important to remember that $1 is not reset after an unsuccessful pattern match - in that case it keeps its previous value.

To get the results texuser74 was getting originally, it seems there was an empty line in xxx.in after the line with the year. When your while loop processed that line, it failed to match <volume>...</volume> but (since you had no if statement), your $vol variable was set to $1 anyway (which was then 2003, as that's the last successful match, from the previous line). It then did the same for the other two variables.