[Israel.pm] FW: defined function

Avishalom Shalit avishalom at gmail.com
Sun Jan 18 01:55:46 PST 2009


so is it ok now ?
i wasn't sure what "doesn't work" means.
a condition is true if a value is defined and is not an empty string or a 0.

look at truth values here http://www.faqs.org/docs/pperl/pickingUpPerl_5.html

2009/1/18 Chanan Berler <chananb at centerity.com>:
> Correction to my little scripto: raiseError => RaiseError, printError => PrintError
> Where needed - found it while testing the script
>
> Chanan
>
> -----Original Message-----
> From: Chanan Berler [mailto:chananb at centerity.com]
> Sent: Sunday, January 18, 2009 11:23 AM
> To: 'Perl in Israel'
> Subject: FW: defined function
>
> 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});
>
>    chomp($lv_msg);
>    print "Error: $lv_msg\n" if ($lv_args{printError} == 1);
>    exit($lv_ec) if ($lv_args{RaiseError} == 1);
>    return $lv_ec;
> }
>
>
> Thanks
> Chanan
>
> -----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
>
> Or
>
> "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
> Chanan
>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl
>



-- 
-- vish



More information about the Perl mailing list