in reply to Two Questions on "my"

In the question 1, the only difference to declare $foo outside of the loop, or inside is not the memory, because Perl will detect that and will reuse the same memory (SV), is the cleanning process for each loop. If you declare outside you only write on $foo one time per loop (when getValue return something). But if you declare $foo inside the for, for each loop the same SV need to be "created" and cleanned. But note that in both cases the SV will be always in the same address.

With a simple test you can see that declare $foo outside of the loop is a little faster, but you will only win speed if you have this loop working for more that 100.000 in your program, and is a little of speed.

Graciliano M. P.
"Creativity is the expression of the liberty".

Replies are listed 'Best First'.
Re: Re: Two Questions on "my"
by Anonymous Monk on May 22, 2004 at 23:36 UTC

    As proof that they're the same address:

    #!/usr/bin/perl -wl for (1..5) { my $i = rand(); print \$i; }