[Israel.pm] Fwd: FW: newbie question

Jason Elbaum jason.elbaum at gmail.com
Thu Jan 15 07:09:17 PST 2009


On Thu, Jan 15, 2009 at 4:05 PM, bc.other <bc.other at gmail.com> wrote:

>
> 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 don't know what nagios is, but I don't understand how you can
possibly need to use variables that can't be defined.

But in any case you can still "use strict;" and then "no strict
'vars'" to turn off undefined variable checking.


>
> 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.

Defined checks whether a variable has been assigned a value or not. By
default all variables contain undef.


>
> Also I know @arr returned a ARRAY(address) - so why can I check it using
> if() maybe because it returns the addres value.

I don't know what you mean here. @arr does not return anything; it is
the name of an array variable. if() checks if it is empty.


>
> So, does my @arr; return 0 ?

Converting an array variable to a scalar value yields the length of the array.



>
> Also, can I compare @arr1 = @arr2 and check if they are allocated to same
> place? Like addresses in C

They can't be allocated to the same place, since they're different
arrays. Each manages its own memory.


Frankly, it sounds to me like you should refresh your memory about
basic Perl concepts. Try the perldata man page for starters.

Good luck,

Jason Elbaum




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



More information about the Perl mailing list