
KevinR
Veteran

Jul 20, 2007, 9:56 AM
Post #4 of 4
(379 views)
|
|
Re: [Clara] A little help still needed on line extraction
[In reply to]
|
Can't Post
|
|
If your code is essentially still written like this:
foreach $file (@line) { chop($file); ($code,$object,$color,$description,$comment)=split(/\,/,$file); } if ($file=~/^$num,/) { print "Code:$code,Object: $object,Color: $color,Description: $description,Comment: $comment"; } the problem is you are checking to see if the two variables match after you have read through the entire array @line. The "if" condition needs to be inside the "foreach" loop:
foreach $file (@line) { chomp($file);#<-- use chomp not chop ($code,$object,$color,$description,$comment)=split(/\,/,$file); if ($code == $num) { print your stuff here } } when you put it outside the foreach loop $code can only ever equal the value of the last line of the array which is why you get the results you have been getting. -------------------------------------------------
|