Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: checking values of variables

by Laurent_R (Canon)
on Aug 12, 2013 at 15:39 UTC ( #1049136=note: print w/replies, xml ) Need Help??


in reply to Re: checking values of variables
in thread checking values of variables

I guess that would not work, because the OP apparently wants to trigger the help function if any of the variables is absent, not if they are all missing.

So using a hash, it would have to be something like this:

help() if 22 > scalar values %params; # scalar unnecessary, just to make the context clearer

But that would not be very robust, for example if the %params may have some elements other that the list of mandatory parameters.

So an approach more reliable than just counting the hash values would be to test each and every single mandatory param:

for (qw / server database user password ... initversion /) { help() and last unless (defined $params{$_} and $params{$_}); }

The exact test on the %params values would depend on how the hash is initialized.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1049136]
help
Chatterbox?
LanX hurts to be bitten between the legs ;-)
[holli]: You see, I have a friend whose daughter has been damaged seriously because she wasn't vaccinated against measles. (Her mother being anti-vaxx).
[LanX]: Contrary to Olivia newton John I don't like physical confrontations ...
[LanX]: Oh, you spread measles in your saliva?
[LanX]: ... and why did you bite hos daughter?
[LanX]: *his
[holli]: And this guy was also Anti-Vaxx and I just snapped. I shoed him all over the yard
[james28909]: biting between the legs? now thats my kind of religion.
[holli]: and back into the building, saw him later peeking out of the window looking scared. It was hilarious.
[LanX]: Let's get physical...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (12)
As of 2017-12-13 18:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (373 votes). Check out past polls.

    Notices?