in reply to problem with variables

You don't need to do s/// - and you're not checking that the regex has actually matched, before copying $1 into your own variables. In other words, all three of your variables get set to $1 each time round the while loop.

Try replacing:

s/<volume>(.*)<\/volume>//;$vol=$1; s/<issue>(.*)<\/issue>//;$iss=$1; s/<year>(.*)<\/year>//;$yr=$1;

with:

$vol = $1 if /<volume>(.*)<\/volume>/; $iss = $1 if /<issue>(.*)<\/issue>/; $yr = $1 if /<year>(.*)<\/year>/;

(Note: untested)


s^^unp(;75N=&9I<V@`ack(u,^;s|\(.+\`|"$`$'\"$&\"\)"|ee;/m.+h/&&print$&

Replies are listed 'Best First'.
Re^2: problem with variables
by ishnid (Monk) on Sep 15, 2004 at 12:11 UTC
    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.
Re^2: problem with variables
by texuser74 (Monk) on Sep 15, 2004 at 09:50 UTC
    hi muntfish,

    Thanks a lot, it works now.