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/