in reply to Anonymous Thingies
Why would you want such a thing?
Probably the simpest example I can think of is when you "need" to pass more than one array or hash (or one of each) to a function. Then you need to pass a reference, and sometimes you are either getting the array from a function or want to hard code it. So you have...
# Passing array refs from function returns... foo([split(',', $a)], [split('/', $b)]); # Passing hard coded data (used in CGI etc.) bar([1..4], { 1 => "foo", 2 => "bar", 3 => "abcd", 4 => "xyz"});
What's the scope on an anonymous thingie?
Probably the easiest thing to do is think of them as named variables, but the names are not in scope, so...
# "anonymous" reference to array of 8 my $foo = [1..8]; ## Is the same as... my $foo = undef; # New scope... { # Array of 8 my @foo = (1..8); # Create reference to array of 8 $foo = \@foo; }
In both cases doing a $foo = undef; will get rid of the last reference to the array.
|
|---|