[Israel.pm] FW: defined function

Chanan Berler chananb at centerity.com
Sun Jan 18 01:23:11 PST 2009

PS: never mentioned it, and might be important I sent the hash to a sub like this:

printWarningError("my msg", 3, ( printError => 0 ));

this is my routine:

sub printWarningError {
    my ($lv_msg, $lv_ec, %lv_args) = @_;  # message to print
    # do nothing if msg not found
    return 0 if ((!$lv_msg) or $lv_msg eq "");
    # defualt values
    $lv_ec = 0 unless $lv_ec;
    $lv_args{printError} = 1 unless defined($lv_args{printError});
    $lv_args{RaiseError} = 1 unless defined($lv_args{RaiseError});
    print "Error: $lv_msg\n" if ($lv_args{printError} == 1);
    exit($lv_ec) if ($lv_args{RaiseError} == 1);
    return $lv_ec;


-----Original Message-----
From: Chanan Berler [mailto:chananb at centerity.com] 
Sent: Sunday, January 18, 2009 11:21 AM
To: 'Perl in Israel'
Subject: defined function

Hi All,

Sure, I will ask again if am asking too many questions…nor if the questions are weird ☺
None the less, I will try ask them...

I was told defined is a function, returns 0 or nonzero values
So here is my question

"do something" unless $myscalar;               -> this is OK
"do something" unless $myhash{mykey};          -> seems not to work for me


"do something" unless defined($myscalar);      -> this is OK
"do something" unless defined($myhash{mykey}); -> now this works for me

What best should I do? Although the answer is in the script body (means using defined)
PS: using now strict / warnings :-) never showed any warnings / errors

Thanks again

More information about the Perl mailing list