develooper Front page | perl.beginners | Postings from March 2002

Reinitializing an Array

Thread Next
From:
Barry Kingsbury
Date:
March 13, 2002 07:30
Subject:
Reinitializing an Array
Message ID:
3C8F70C7.7CCA27D5@etnus.com
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?


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About