Practical Perl wrote:
Hi,list,
When a subroutine return a value,for example,this value is a pointer to an
array,which is get defined in this subroutine.When out of the
subroutine,some a statement call this subroutine and receive the return
value to a variable named as $aaa.Is $aaa a duplicate of the pointer in that
subroutine?Thanks.
sub test {
@abc = qw/aa bb cc dd/;
return [EMAIL PROTECTED];
}
my $aaa = test( );
It's not a pointer, it's a reference. They work differently than
pointers. In the above, $aaa is a reference to the array @abc, which,
btw, is a global. Had you written:
sub test {
my @abc = qw/aa bb cc dd/; # scoped inside the subroutine
return [EMAIL PROTECTED];
}
my $aaa = test();
__END__
Now it looks like $aaa is a reference to an array which is out of scope
but Perl keeps a count of all references to a thingy and only when this
count reaches zero does it delete them.
So if you:
print "@$aaa\n";
you will see:
aa bb cc dd
on the output.
--
Just my 0.00000002 million dollars worth,
--- Shawn
"For the things we have to learn before we can do them,
we learn by doing them."
Aristotle
"The man who sets out to carry a cat by its tail learns something that
will always be useful and which will never grow dim or doubtful."
Mark Twain
"Believe in the Divine, but paddle away from the rocks."
Hindu Proverb
* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is at http://perldoc.perl.org/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>