[Israel.pm] FW: newbie question

bc.other bc.other at gmail.com
Thu Jan 15 06:05:00 PST 2009

First of all, although I mentioned being a newbie, I do got couple of years
of programming (4+ years already).
Just needed some clarification about something, since it's been a while
since I coded in perl.

By the way, my scripts are one exception when you must not use the strict /
warning modules.
Since it's coded for working with nagios engine, and needed some variables
to be used in some stages where
The same variables couldn't be defined.

I tried coding first with strict, but it showed too many warnings, which
couldn't be avoided.
As for my questions:

I know the if () statement compares the values to 0, same as in C, C++
But I wonder if defined does something with the arguments sent to it - like
check allocation to memory or so.

Also I know @arr returned a ARRAY(address) - so why can I check it using
if() maybe because it returns the addres value.
So, does my @arr; return 0 ?
Also, can I compare @arr1 = @arr2 and check if they are allocated to same
place? Like addresses in C


-----Original Message-----
From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On Behalf
Of Gaal Yahas
Sent: Thursday, January 15, 2009 3:41 PM
To: Perl in Israel
Subject: Re: [Israel.pm] FW: newbie question

On Thu, Jan 15, 2009 at 3:22 PM, Chanan Berler <chananb at centerity.com>
> 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
> 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.

> or
> do_something if (defined($legend));

This will do_something when $legend is zero or the empty string.

> or
> 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 = ();
> And
> @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);
> thanks
> Chanan
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl

Gaal Yahas <gaal at forum2.org>
Perl mailing list
Perl at perl.org.il

More information about the Perl mailing list