Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Re: "or" or "||" problems

by Silicon Cactus (Scribe)
on Nov 07, 2002 at 13:09 UTC ( [id://211058]=note: print w/replies, xml ) Need Help??


in reply to Re: "or" or "||" problems
in thread "or" or "||" problems

Thanks so much. The regex was b0rked, yes. :) Although my actual code has it correct. -That's what I get for posting after boiling my brain. <grin>
I should have thought about the 'next unless $_'. That makes much more sense than what I was doing.
Also, to avoid the ridicule about my flag being global that is mentioned below, it wasn't. :) I just neglected to post the other declarations in the sub that were outside my loop.

Anyways, thanks again. :)

Replies are listed 'Best First'.
Re: Re: Re: "or" or "||" problems
by tachyon (Chancellor) on Nov 07, 2002 at 14:18 UTC

    You could get really fancy if you wanted. When validating input via CGI I ususally use $err_msg as a flag. I use it like this:

    ############ VALIDATE USER DATA ############# my $err_msg = ''; # check valid date format $err_msg .= "<p>Wrong date format '$date', use YYYY-MM-DD\n" unless $date =~ m#(\d{4})\-(\d{2})\-(\d{2})#; my $year = $1 || ''; my $month = $2 || ''; my $day = $3 || ''; # check year $err_msg .= "<p>Invalid year '$year'\n" unless $year > 1970 and $year +< 2100; # check month # blah # check day # blah # check other input adding error messages to $err_msg do { show_error_page($err_msg); exit } if $err_msg; ########### ONLY GET HERE IF INPUT VALID ########## do_work()

    I like this because you validate all your input and respond with a comprehensive error message(s). You use $err_msg (which contains elpanatory error text) as the flag, killing two birds with one scalar.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-18 17:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found