Re: Reinitializing an Array

2002-03-14 Thread John W. Krahn

[message rearranged chronologically - please don't top-post]


Luke wrote:
 
 From: John W. Krahn [EMAIL PROTECTED]
 
  Barry Kingsbury wrote:
  
   I have an array that I wish to reuse. Before I reuse it, I want to clear
 out all
   elements. Both of the following seem to work:
  
   @an_array = ;
 
  This does not clear out all elements, it assigns one element to
  @an_array with the value of .
 
 
   and
  
   $#an_array = -1;
 
  This is one way to do it properly, another way is:
 
   @an_array = ();
 
  This assigns an empty list to @an_array.
 
 you can always set it to undef also:
 
 @an_array=undef;

This does not clear out all elements, it assigns one element to
@an_array with the value of undef.


John
-- 
use Perl;
program
fulfillment

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




RE: Reinitializing an Array

2002-03-13 Thread Nikola Janceski

proper way:

@an_array = ();

or

undef @an_array; # doesn't really free up the memory it used but the array
is uninitialized

-Original Message-
From: Barry Kingsbury [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, March 13, 2002 10:31 AM
To: [EMAIL PROTECTED]
Subject: Reinitializing an Array


I have an array that I wish to reuse. Before I reuse it, I want to clear out
all

elements. Both of the following seem to work:

@an_array = ;

and

$#an_array = -1;

I then go on to do something like:

foreach (@foo_array) {
   push (@an_array, $_);
}

Neither seems completely correct although I like the second. Is the second
legal
and
portable or did I just luck out?

Is there a better way?


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



The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


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




Re: Reinitializing an Array

2002-03-13 Thread John W. Krahn

Barry Kingsbury wrote:
 
 I have an array that I wish to reuse. Before I reuse it, I want to clear out all
 elements. Both of the following seem to work:
 
 @an_array = ;

This does not clear out all elements, it assigns one element to
@an_array with the value of .


 and
 
 $#an_array = -1;

This is one way to do it properly, another way is:

 @an_array = ();

This assigns an empty list to @an_array.



John
-- 
use Perl;
program
fulfillment

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




Re: Reinitializing an Array

2002-03-13 Thread luke

you can always set it to undef also:

@an_array=undef;

---
Luke Davison
[EMAIL PROTECTED]

- Original Message -
From: John W. Krahn [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, March 13, 2002 2:59 PM
Subject: Re: Reinitializing an Array


 Barry Kingsbury wrote:
 
  I have an array that I wish to reuse. Before I reuse it, I want to clear
out all
  elements. Both of the following seem to work:
 
  @an_array = ;

 This does not clear out all elements, it assigns one element to
 @an_array with the value of .


  and
 
  $#an_array = -1;

 This is one way to do it properly, another way is:

  @an_array = ();

 This assigns an empty list to @an_array.



 John
 --
 use Perl;
 program
 fulfillment

 --
 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: Reinitializing an Array

2002-03-13 Thread Timothy Johnson

 
If you're having this kind of trouble, chances are you might not be properly
scoping your array.  Try declaring the array using my() inside of the scope
you wish to use, for example inside of a loop.  Then you won't have to worry
about whether you remembered to undef your array.

-Original Message-
From: luke
To: [EMAIL PROTECTED]
Sent: 3/13/02 3:35 PM
Subject: Re: Reinitializing an Array

you can always set it to undef also:

@an_array=undef;

---
Luke Davison
[EMAIL PROTECTED]

- Original Message -
From: John W. Krahn [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, March 13, 2002 2:59 PM
Subject: Re: Reinitializing an Array


 Barry Kingsbury wrote:
 
  I have an array that I wish to reuse. Before I reuse it, I want to
clear
out all
  elements. Both of the following seem to work:
 
  @an_array = ;

 This does not clear out all elements, it assigns one element to
 @an_array with the value of .


  and
 
  $#an_array = -1;

 This is one way to do it properly, another way is:

  @an_array = ();

 This assigns an empty list to @an_array.



 John
 --
 use Perl;
 program
 fulfillment

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



This email may contain confidential and privileged 
material for the sole use of the intended recipient. 
If you are not the intended recipient, please contact 
the sender and delete all copies.

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