[Israel.pm] FW: FW: defined function

bc.other bc.other at gmail.com
Sun Jan 18 02:10:39 PST 2009


Checking with my values, my mistake - sorry
Found that I was sending the value 0 to the hash value - therefore it results same as !defined.
Please ignore my question - should have tested the values myself - before raising the question.

Sorry again
Chanan

-----Original Message-----
From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On Behalf Of Avishalom Shalit
Sent: Sunday, January 18, 2009 11:56 AM
To: Perl in Israel
Subject: Re: [Israel.pm] FW: defined function

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
_______________________________________________
Perl mailing list
Perl at perl.org.il
http://perl.org.il/mailman/listinfo/perl




More information about the Perl mailing list