If you read my original email, I said it was a bad idea and also that you
would need to turn strict off to do anything like that. 
The example below declared the arrays on the fly with strict not in place. 

-----Original Message-----
From: Paul Lalli [mailto:[EMAIL PROTECTED] 
Sent: 15 August 2007 15:08
To: beginners@perl.org
Subject: Re: Emptying several arrays at once

On Aug 14, 10:17 pm, [EMAIL PROTECTED] (Jeff Pang) wrote:
> >From: Andrew Curry <[EMAIL PROTECTED]>
>
> >Whilst you can do by turning off strict and using an array of 
> >arraynames and looping over them, its clear concise the way you are doing
it.
>
> >I think you could do something like
>
> >@arrays=('test1','test2','test3');
>
> >foreach my $array(@arrays) {
> >@{$array}=();
> >}
>
> This wouldn't work.

Correction.  This MIGHT NOT work.  Two things have to be true:  (1) strict
'refs' needs to be disabled, and (2) the arrays in question must be global,
not lexical:

$ perl -MData::Dumper -le'
@foo = (1, 2, 3);
@bar = (qw/alpha beta/);
for my $array ("foo", "bar") {
   @{$array} = ();
}
print Dumper([EMAIL PROTECTED], [EMAIL PROTECTED]);
'
$VAR1 = [];
$VAR2 = [];


> test1,test2,test3 are not array reference,saying @{$array} would get
wrong.

Not if you turn off strict like the poster suggested.  Then symrefs are
allowed, and you can access the an array by pretending that a string
containing the name of the array is an array reference.

This is not, however, a good idea.

Paul Lalli


--
To unsubscribe, e-mail: [EMAIL PROTECTED] For additional
commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/



This e-mail is from the PA Group.  For more information, see
www.thepagroup.com.

This e-mail may contain confidential information.  Only the addressee is
permitted to read, copy, distribute or otherwise use this email or any
attachments.  If you have received it in error, please contact the sender
immediately.  Any opinion expressed in this e-mail is personal to the sender
and may not reflect the opinion of the PA Group.

Any e-mail reply to this address may be subject to interception or
monitoring for operational reasons or for lawful business practices.





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to