in reply to *FOO{THING} syntax used on a lexical variable

The trick is that the *FOO{THING} syntax works on typeglobs. Package variables are in typeglobs. But typeglobs need not be package variables.

My comment might make more sense if you go back to how we did that with Perl 5.005.

use strict; use warnings; my $fh = do {local *FOO}; open $fh, "somefile"; my $sc = *$fh{IO}; print <$sc>;
Is it less surprising now?

Replies are listed 'Best First'.
Re^2: *FOO{THING} syntax used on a lexical variable
by revdiablo (Prior) on Jun 12, 2005 at 07:28 UTC
    *FOO{THING} syntax works on typeglobs

    Ah, that's what I was missing. I knew there was a simple explanation! Thanks for your reply. For further reinforcement of your point:

    $ perl -le 'open my $fh, "file"; print $fh;' GLOB(0x814cc20)

    And to show some symmetry with the package variable variety of typeglob:

    open FOO, "file"; print ref \*FOO; # prints GLOB open my $fh, "file"; print ref \*$fh; # prints GLOB