[EMAIL PROTECTED] wrote:
Paul Lalli wrote:
On Aug 14, 10:17 pm, [EMAIL PROTECTED] (Jeff Pang) wrote:
From: Andrew Curry <[EMAIL PROTECTED]>
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.
Yes you know this is not a good idea.I don't like to say what,but someone
others maybe say,
DON'T SUGGEST THIS BAD IDEA!
Hey, please don't shout! Paul didn't _suggest_ anything, AFAICT, but
rather corrected your post, which contains incorrect statements.
Andrew's suggested code works just fine, albait not under strict:
C:\home>type test.pl
@test1 = qw/1 2 3/;
@test2 = qw/4 5 6/;
@test3 = qw/7 8 9/;
@arrays=('test1','test2','test3');
foreach my $array(@arrays) {
@{$array}=();
}
C:\home>perl test.pl
C:\home>
What's considered a good practice is quite another thing.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/