fbicknel has asked for the wisdom of the Perl Monks concerning the following question:

Anyone know how this code works? This is from File::Temp
# Store the filename in the scalar slot ${*$fh} = $path;
What is this scalar slot (and he uses something similar a few lines later for a hash slot)?

Later in ->filename, he pulls the value from this 'slot' for the filename.

We know that *$fh evaluates to a string, but how does he get away with assigning to this variable when use strict is on?

Replies are listed 'Best First'.
Re: Obscure ${foo} reference
by rwstauner (Acolyte) on Sep 10, 2011 at 19:48 UTC

    the $fh variable is a glob reference... something like *Symbol::GEN0.

    ${*$fh} dereferences the glob to access a slot in the symbol table (which is what a glob is).

    Assigning a scalar value (the right side of the expression) to a slot in the symbol table puts it in the SCALAR slot.

    See also when I asked this question: symbol/glob hash explanation

      Correct, but ...

      Speaking of the symbol table I would avoid "slot" in favour of "entry" or "element".

      A glob is a simple hash "entry", and it's the glob which has (IIRC) exactly 6 "slots".

      Cheers Rolf