undefine @array

G

George Mpouras

I want to delete an array completly.

use strict; use warnings; my
@array=qw/a b c/;
@array=();
undef @array;
print @array;

I expect a warning like "Global symbol "@array" requires explicit..." but it
did not compaint
 
T

Tim McDaniel

George Mpouras said:
I expect a warning like "Global symbol "@array" requires explicit..."
but it did not compaint

but later
yes I want to clear symbol @array completly but at the same scope

These goals are not consistent. As Eli explained, that is not
possible in Perl.

If you clear an array, like
my @array;
...
@array = ();
or
my @array;
...
undef @array;
that sets @array to have zero elements, but @array still exists as a
variable and you will not get a message for using @array later.

"Global symbol ... requires explicit" is an error, not a warning, so
far as I know. The only way to get that error is to declare @array in
a scope that ends, like
{
my @array = (12, 14, 16);
...
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top