Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Or Operator

by Avitar (Acolyte)
on Jul 30, 2004 at 23:15 UTC ( #378833=note: print w/replies, xml ) Need Help??

in reply to Or Operator

my $page = $cgi->param("page") Or "login";

should prob be rewritten as a conditional statement for clairy...

my($page) = $cgi->param("page"); if($page eq ""){ $page = "login";}

Try it with a lowercase 'or'; Remember if it is worth writing, it is worth writing clear... if possible even difficult code should be understandable by even the most unexperianced.

Replies are listed 'Best First'.
Re^2: Or Operator
by beable (Friar) on Jul 31, 2004 at 01:40 UTC
    I think this is the clearest and most concise way to express it: my $page = $cgi->param("page") || "login"; You might say that inexperienced people won't understand it, but once they see it a few hundred times (because this is a very common way of doing it), they'll probably get it.
      Then again, if there is a chance that $cgi->param("page") will be 0 - and you want to accept that, || will not work correctly. We'll get // (defined-or) in Perl 5.10, fortunately.
Re^2: Or Operator
by Aristotle (Chancellor) on Jul 31, 2004 at 19:31 UTC

    Except that will give you warnings if the page parameter is actually non-existent.

    You want to test definedness as well as emptiness.

    my $page = $cgi->param( "page" ); unless( defined $page and $page ne "" ){ $page = "login"; }

    Of course that's pretty clusmy and contains lots of unnecessary punctuation. Let's use a statement modifier instead:

    my $page = $cgi->param("page"); $page = "login" unless defined $page and $page ne "";

    Makeshifts last the longest.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://378833]
[karlgoethebier]: LanX: no cuke?
[karlgoethebier]: btw, Churchill preferred 12 of these drinks instead of diet coke...
[LanX]: KGB that's amatter of perspective
[erix]: when you name is KirchenHuegel you want some compensation
LanX was googling for Kirchenhügel ... till he realized someone is translating Church-Hill to German... (slapping forhead)

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2017-12-12 16:21 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (335 votes). Check out past polls.