<answer>
i agree with you,
but for the sake of read - a - bility I would have defined
the vars here (<---) as they are valid for whole package anyway and not
just for test1();

use strict;

local $a = 1;   <---
local $aa = 2;  <---

test1();

sub test1
{
   test2();
}

sub test2
{
   print "a = $a\n";
   print "aa = $aa\n";
}
</answer>
Wiggins d'Anconia wrote:

> Eternius wrote:
>
>> Joshua A. Gage wrote:
[snip]
>>
>> use my
>> extract from perldoc -f my :
>>  A "my" declares the listed variables to be local
>>                (lexically) to the enclosing block, file, or
>>                "eval".
>>
>
> In most cases  you would be right, but in this case it appears that the
> OP understands what 'local' does, as he is using it inside of an
> embedded function. Do I like that, no, but it is a "correct" usage of
> 'local'.  Your suggestion of using 'my' changes how the variables must
> be used so is not equivalent without suggesting the interface to 'test2'
> changes...
>
> sub test1 {
>   my $aa = 1;
>   my $aaa = 2;
>   test2($aa, $aaa);
> }
>
> sub test2 {
>   my ($bb, $bbb) = @_;
>   print "aa = $bb\n";
>   print "aaa = $bbb\n";
> }
>
> Is the above better, in the court of readability and encapsulation, yes,
> in the court of elegance, maybe not...
>
> http://danconia.org
>
>
>

--
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