Help with clearing an array

2002-01-13 Thread Michael Eggleton

Hello all,

  Could some one help me with clearing or re-setting and array.

  I have an array that has an unknow number of elements in it, at one 
point in my program I would like to clear that array or reset it so 
that it contains nothing.  How do I do that?

Thanks

Michael D. Eggleton
http://www.gorealnetworks.com
mailto:[EMAIL PROTECTED]



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




Re: Help with clearing an array

2002-01-13 Thread Eric Beaudoin

At 00:39 2002.01.14, Michael Eggleton wrote:
>Hello all,
>
>  Could some one help me with clearing or re-setting and array.
>
>  I have an array that has an unknow number of elements in it, at one 
>point in my program I would like to clear that array or reset it so 
>that it contains nothing.  How do I do that?
>
>Thanks


@array = ();  # Note the usage of @ and not $.

Hope it helps


---
Éric Beaudoin


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




Re: Help with clearing an array

2002-01-13 Thread Steve Maroney


@my_arry = "";


On Mon, 14 Jan 2002, Michael Eggleton wrote:

> Hello all,
>
>   Could some one help me with clearing or re-setting and array.
>
>   I have an array that has an unknow number of elements in it, at one
> point in my program I would like to clear that array or reset it so
> that it contains nothing.  How do I do that?
>
> Thanks
>
> Michael D. Eggleton
> http://www.gorealnetworks.com
> mailto:[EMAIL PROTECTED]
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>








Thank you,
Steve Maroney





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




Re: Help with clearing an array

2002-01-13 Thread Leon

- Original Message - 
From: "Steve Maroney" <[EMAIL PROTECTED]>
To: "Michael Eggleton" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Sunday, January 13, 2002 11:12 PM
Subject: Re: Help with clearing an array


> 
> @my_arry = "";

Can I use this :-
@my_arry = undef;

Thanks.


_
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


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




Re: Help with clearing an array

2002-01-14 Thread Steven Brooks

On Monday 14 January 2002 04:54 pm, you wrote:
> Can I use this :-
> @my_arry = undef;

No, because it doesn't clear the array.  Read the following quote:

Small quote from "Learning Perl" page 53 - under the section "Using
Scalar-Producing Expressions in a List Context"
<>
Going this direction is straightforward: if an expression doesn't normally
have a list value, the scalar value is automatically promoted to make a
one-element list:

@fred = 6 * 7; # gets the one-element list (42)
@barney = "hello" . ' ' . "world";

Well, there's one possible catch:

@wilma = undef; # OOPS! Gets the one-element list (undef)
# which is not the same as this:
@betty = ();# A correct way to empty an array

Since undef is a scalar value, assigning undef to an array doesn't clear the
array.  The better way to do this is to assign an empty list
<>


Steven

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




Re: Help with clearing an array

2002-01-14 Thread John W. Krahn

Leon wrote:
> 
> From: "Steve Maroney" <[EMAIL PROTECTED]>
> >
> > @my_arry = "";
> 
> Can I use this :-
> @my_arry = undef;


$ perl -le'
@array = qw(1 2 3 4 5);
print scalar @array, ": @array";
@array = "";
print scalar @array, ": @array";
@array = qw(1 2 3 4 5);
@array = undef;
print scalar @array, ": @array";
@array = qw(1 2 3 4 5);
@array = ();
print scalar @array, ": @array";
'
5: 1 2 3 4 5
1: 
1: 
0: 


As you can see @array = ""; and @array = undef; don't clear the array.



John
-- 
use Perl;
program
fulfillment

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




Re: Help with clearing an array

2002-01-14 Thread Connie Chan

Hee.. @my_arry = undef; will make the array carrying 1 element --> undef
it will not be a blank array =)

have a nice day

- Original Message - 
From: "Leon" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, January 15, 2002 7:54 AM
Subject: Re: Help with clearing an array


> - Original Message - 
> From: "Steve Maroney" <[EMAIL PROTECTED]>
> To: "Michael Eggleton" <[EMAIL PROTECTED]>
> Cc: <[EMAIL PROTECTED]>
> Sent: Sunday, January 13, 2002 11:12 PM
> Subject: Re: Help with clearing an array
> 
> 
> > 
> > @my_arry = "";
> 
> Can I use this :-
> @my_arry = undef;
> 
> Thanks.
> 
> 
> 
> _
> 
> Do You Yahoo!?
> 
> Get your free @yahoo.com address at http://mail.yahoo.com
> 
> 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 


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




Re: Help with clearing an array

2002-01-14 Thread Leon

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


_
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


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




Re: Help with clearing an array

2002-01-14 Thread Curtis Poe

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




RE: Help with clearing an array

2002-01-14 Thread Stout, Joel R

perldoc perldata says for clearing arrays:

@array = ();

or...

$#array = -1;


> -Original Message-
> From: Leon [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, January 15, 2002 8:19 AM
> To: [EMAIL PROTECTED]
> Subject: Re: Help with clearing an array
> 
> 
> - 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.
> 
> 
> _
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

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