[Israel.pm] FW: newbie question
gaal at forum2.org
Thu Jan 15 05:41:19 PST 2009
On Thu, Jan 15, 2009 at 3:22 PM, Chanan Berler <chananb at centerity.com> wrote:
> Hi All,
> I am wondering if there is a difference between:
> The last one I believe I know the answer, empty string still defined, but I
> sure wanna clear view..:-)
> PS: will use strict / warning will make a difference ?
This question implicates you for not using strict. Use strict. :-)
> do_somthing if ($legend);
This is a good test if you don't know anything about $legend. It won't
cause a warning when $legend is undefined. You may omit the
parentheses here, BTW.
> do_something if (defined($legend));
This will do_something when $legend is zero or the empty string.
> do_something if ($legend == "");
Run this and read the warning. It should be valuable to you.
If you really want string comparison, use eq, not ==.
> another question:
> is there a difference between
> @arr = ();
"@arr" on a line of its own doesn't mean anything (except to give away
that you aren't using strict).
@arr = () clears the array (sets it to length zero).
my @arr and my @arr = () are equivalent.
> Since both of them showed nothing when trying to do this:
> print "Yea" if (@arr);
> Perl mailing list
> Perl at perl.org.il
Gaal Yahas <gaal at forum2.org>
More information about the Perl