Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Using currently selected filehandle

by particle (Vicar)
on Jun 23, 2003 at 18:26 UTC ( [id://268267]=note: print w/replies, xml ) Need Help??


in reply to Using currently selected filehandle

#!/usr/bin/perl -w use strict; local *FH= select; print FH "Hello\n";

~Particle *accelerates*

Replies are listed 'Best First'.
Re: Re: Using currently selected filehandle
by chip (Curate) on Jun 23, 2003 at 18:54 UTC
    I'd call that a bug in use strict, to allow a symbolic glob ref like that. On the other hand, by the time you're playing with glob aliasing, what's a little symbolic reference between friends? :-,

        -- Chip Salzenberg, Free-Floating Agent of Chaos

      that's no bug, Chip. print accepts a filehandle as the first parameter. filehandles can be accessed as barewords, as they are in many places, such as open FH, '>', '/dev/null' or die $!;. filehandles are either referenced as barewords, or as foo-thing syntax: *FH{IO}.

      ~Particle *accelerates*

        Your comment would be correct if the only purpose of glob aliasing were for naming filehandles. That's not the case at all. Glob aliasing is used for all sorts of namespace games. And many of those games are quite dangerous ... the kinds of things I'd have liked use strict to complain about. sigh

            -- Chip Salzenberg, Free-Floating Agent of Chaos

Re: Re: Using currently selected filehandle
by sgifford (Prior) on Jun 23, 2003 at 18:48 UTC

    Thanks, that's exactly what I was looking for.

    What's going on there? Is select being called in a typeglob context, and so returning a typeglob instead of a string?

      there is no typeglob context, but you're on to something. when you assign the result from select to a scalar, it stringifies the IO type that select normally returns. since there's no sigil for an IO type, you usually assign to it through a typeglob. since typeglobs cannot be lexical, you cannot use my to limit their scope. instead, you must use local, which will limit their scope to the current block, and create the typeglob, if it doesn't already exist.

      hope that helps.

      ~Particle *accelerates*

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-25 20:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found