--- Leon <[EMAIL PROTECTED]> wrote:
> ----- Original Message -----
> From: "John W. Krahn" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> 
> > @array = qw(1 2 3 4 5);
> > @array = ();
> > print scalar @array, ": @array";
> > 0:
> >
> > As you can see @array = ""; and @array = undef; don't clear the array.
> 
> This gives me an idea of assigning 0 for clearing of arrays, scalar or
> hashes;
> eg :-
> my ($scalar , @array , %hash ) = ();
> or
> my $scalar = 0;
> my @array = 0;
> my %hash = 0;
> 
> Are the above acceptable? Seems to be.

Actually, they are not doing what you think they are doing.  The problem stems from
misunderstanding this snippet of code:

> print scalar @array, ": @array";
> 0:

Accessing an array in scalar context returns the number of elements in the array (in 
this case,
none).  This should be evident from the fact that interpolating the array in quotes 
reveals no
elements.  Contrast that to this, which should show the difference:

    $ perl -e '
    my @array = 0;
    print scalar @array, ":@array"'
    1:0

In scalar context, we see that @array has one element, and when interpolated, we see 
that this
element is zero (e.g. $array[0] == 0).

Cheers,
Curtis "Ovid" Poe

=====
"Ovid" on http://www.perlmonks.org/
Someone asked me how to count to 10 in Perl:
push@A,$_ for reverse q.e...q.n.;for(@A){$_=unpack(q|c|,$_);@a=split//;
shift@a;shift@a if $a[$[]eq$[;$_=join q||,@a};print $_,$/for reverse @A

__________________________________________________
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to