develooper Front page | perl.perl5.porters | Postings from August 2001

Re: [ID 20010731.067] local($#array) is not local :(

Thread Previous | Thread Next
From:
Michael G Schwern
Date:
August 5, 2001 13:22
Subject:
Re: [ID 20010731.067] local($#array) is not local :(
Message ID:
20010801075554.A753@blackrider
On Tue, Jul 31, 2001 at 03:05:10PM -0400, Jeff Pinyan wrote:
>   @a = (1..5);
>   {
>     local $#a = 2;
>     print "@a\n";
>   }
>   print "@a\n";
> 
>   __END__
>   1 2 3
>   1 2 3
> 
> That's a bit discouraging.

Hmmm.  Doesn't even do what I thought it would do (ie. return $#a to
5 but leave @a[3,4] empty).  What should it do?


Anyhow, you can get the desired effect with:

    @a = (1..5);
    {
        local @a = @a[0..2];
        print "@a\n";
    }
    print "@a\n";


-- 

Michael G. Schwern   <schwern@pobox.com>    http://www.pobox.com/~schwern/
Perl6 Quality Assurance     <perl-qa@perl.org>	     Kwalitee Is Job One
We have cornered the market on senselessness and have profited.

Thread Previous | 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