Pine Yan wrote:
> Hi,

Hello,

> what happens to the memory space with the following code:
> 
> my @full_list = ();
> 
> if (...) {
>   my @tmp_list;
>   @tmp_list = split(...);

No need for two statements there:

    my @tmp_list = split(...);

>   @full_list = (@full_list, [EMAIL PROTECTED]);
> }
> 
> 
> Here @tmp_list is a local variable and its definition terminates at the
> end of this code segment. Does this mean the
> memory space it occupies will be freed, too? If yes, what will happen to
> the reference of that variable stored in @full_list?

Perl keeps a reference count of variables and since a reference to @tmp_list
is still in existence after the block ends the memory occupied by that
variable will still exist.

You have a bigger problem with the statement:

  @full_list = (@full_list, [EMAIL PROTECTED]);

because you have two copies of @full_list in memory.  You should use push()
for that:

  push @full_list, [EMAIL PROTECTED];



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to