texuser74 has asked for the wisdom of the Perl Monks concerning the following question:
I have an input file with the following input
I want to print these values to a new file. But my following script always prints the same value for all the variables. It always prints the last variable's value. i.e year.<volume>4</volume> <issue>12</issue> <year>2003</year>
Present Outputopen (IN, "<xxx.in"); while(<IN>) { s/<volume>(.*)<\/volume>//;$vol=$1; s/<issue>(.*)<\/issue>//;$iss=$1; s/<year>(.*)<\/year>//;$yr=$1; } close(IN); print "Volume: $vol\n"; print "Issue: $iss\n"; print "Year: $yr\n";
Required Output:Volume: 2003 Issue: 2003 Year: 2003
Please help me in correcting this.Volume: 4 Issue: 12 Year: 2003
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: problem with variables
by muntfish (Chaplain) on Sep 15, 2004 at 09:45 UTC | |
by ishnid (Monk) on Sep 15, 2004 at 12:11 UTC | |
by texuser74 (Monk) on Sep 15, 2004 at 09:50 UTC | |
|
Re: problem with variables
by zejames (Hermit) on Sep 15, 2004 at 10:03 UTC | |
by rvosa (Curate) on Sep 15, 2004 at 21:01 UTC | |
|
Re: problem with variables
by gothic_mallard (Pilgrim) on Sep 15, 2004 at 13:17 UTC |