Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Globs and globals

by BrentDax (Hermit)
on Jan 25, 2005 at 07:58 UTC ( [id://424800]=note: print w/replies, xml ) Need Help??

in reply to Globs and globals

The easiest way might be to just localize S1 and S2 first:

local(*S1, *S2); in your first example...

OTOH, I don't think my $socket \*S1 is valid Perl--maybe there's an equal sign missing between $socket and \*S1?

--Brent Dax
There is no sig.

Replies are listed 'Best First'.
Re^2: Globs and globals
by Eyck (Priest) on Jan 25, 2005 at 13:48 UTC

    This advice is factually incorrect.

    GLOB is a glob, and local doesen't help here ( besides providing false sense of security )

    my $socket=\*S1; print "Orig:",$socket,"\n"; { local(*S1, *S2); my $s=\*S1; print "Local: ",$s,"\n"; }
    Local: GLOB(0x8160be4)

      Odd--you're right, though I can't figure out why. The docs seem to say that you get a new glob when you localize:

      The construct local *name; creates a whole new symbol table entry for the glob "name" in the current package. That means that all variables in its glob slot ($name, @name, %name, &name, and the "name" filehandle) are dynamically reset.

      In any case, the following does work correctly:

      open(S1, "/dev/null"); $a=*S1{IO}; { local(*S1); open(S1, "/dev/null"); $b=*S1{IO}; } print "$a $b\n";
      IO::Handle=IO(0x101536f8) IO::Handle=IO(0x1013cdec)

      --Brent Dax
      There is no sig.

        Interesting, your code works, although I would expect it not to. I haven't seen this excerpt in documentation about local and globs so it's a bit of surprise for me, thanks.

        There must be something about dual nature of globs - whatever experiment you devise it proves your theory, even if it contradicts other experiments.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://424800]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (1)
As of 2024-07-23 05:35 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.