in reply to working with foreach, nestd if's inside

update: When I posted this answer I didn't realize this was in discussions, I followed a CB link, this should be moved or reaped

I'm not sure I get your question but If you have problems exiting a loop I think you need to read about flow control, see next and last (and also continue) availible via perldoc -f for more info on the topic.

  • Comment on Re: working with foreach, nestd if's inside

Replies are listed 'Best First'.
Re: Re: working with foreach, nestd if's inside
by Anonymous Monk on Jun 12, 2002 at 04:24 UTC
    foreach $line (@user) { chomp($line); ($name, $site, $site_id, $des, $email, $pass) = split(/\|/,$ +line); $pass2 = crypt($q->param('pass'), r); if($q->param('user') eq $site_id) { if($pass2 eq $pass) { &start; } else { &error("Password Incorrect"); } } else { &error("Username does not exist"); last;} } }
    --------
    else { &error("Username does not exist"); last;}
    I tried last and it prints once, but it alwats says Username does not exist, I can't get around it.