Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: data field extraction not as expected

by elusion (Curate)
on Dec 06, 2002 at 22:21 UTC ( #218169=note: print w/replies, xml ) Need Help??


in reply to data field extraction not as expected

Your problem is here:
while (my $line =<FILE>) { my ($one,$two,$three,$four,$five) = split "\t",$line; if ($three eq $checkthree) { print "<p>With matching parameters I should be able to see this + </p>"; last; } else { print "<p>If I put the else statement in it ignores the fact t +hat the parameters match - and comes here! (But I don't know why).</ +p>"; last; } }
This is what's happening: You're getting to this while statement, and $line gets the first line from the file. You're finding that the first line of the file doesn't match $checkthree, so the else is executed, the line is printed, and the while is exited. To fix this, try some like the following.
my $matched; while (my $line = <FILE>) { my ($one,$two,$three,$four,$five) = split "\t",$line; if ($three eq $checkthree) { print "<p>With matching parameters I should be able to see thi +s </p>"; $matched = 1; last; } } unless ($matched) { # this is like the else print "<p>If I put the else statement in it ignores the fact that +the parameters match - and comes here! (But I don't know why).</p>"; }

elusion : http://matt.diephouse.com

Replies are listed 'Best First'.
Re: Re: data field extraction not as expected
by jonnyfolk (Vicar) on Dec 07, 2002 at 17:11 UTC
    Thanks very much, elusion. The explanation was very clear and the solution works perfectly!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://218169]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2019-07-22 09:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If you were the first to set foot on the Moon, what would be your epigram?






    Results (12 votes). Check out past polls.

    Notices?