Sorry, just posted to Jeff only. 

Thanks for the answer but what I want to know is the meaning of %$$self. I 
understand autovivification ( data structures spring into existence ). 
However, the part I don't understand is %$$self. Shouldn't it be %$self? ( 
By the definition, you can always put a reference in place of the literal 
in the variable.
i.e. $self{k} and $$reftoself{k}.  Replacing "self" with "$reftoself" is 
equivalent.
---- Thanks 
Atul
 




Jeff 'japhy/Marillion' Pinyan <[EMAIL PROTECTED]>
09/18/01 08:14 PM
Please respond to japhy

 
        To:     [EMAIL PROTECTED]
        cc:     [EMAIL PROTECTED]
        Subject:        Re: autovivification of typeglobs


On Sep 18, [EMAIL PROTECTED] said:

>open my $self, $from, @_ or croak "can't open $from@_:$!";

>" ... the my $self furnishes undefined scalar to open, which knows to 
>autovivify it into a typeglob. .... " and further mentions autovivifying 
a 

When you use an undefined value as a reference, Perl creates that
reference for you automatically.  THAT is autovivification.  Thus, when
you do:

  my $x;
  $x->{foo} = 10;
  $x->{bar}[5] = 20;

You've autovivified $x as a hash reference from the second line, and
autovivified $x->{bar} as an array reference on the third line.

When you do:

  open my($foo), $path;

Perl is expecting a typeglob.  If you give it an undefined value, it
autovivifies the typeglob reference, so *$foo is the filehandle.  However,
references to filehandles are accepted wherever a filehandle is, so you
can just use $foo and get away with it.

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to