[OT] perl file handle question

Nicholas Clark nick at ccl4.org
Mon Mar 17 22:15:57 GMT 2008


On Sat, Mar 15, 2008 at 07:51:48PM +0000, Paul LeoNerd Evans wrote:
> On Sat, 15 Mar 2008 18:50:09 +0000
> Nicholas Clark <nick at ccl4.org> wrote:
> 
> > Is there a good clean way to have something that mostly behaves as a file
> > handle, but has the file name squirrelled away in it somehow?
> 
> A filehandle is a GLOB ref, yes? The actual IO work uses the {IO} portion

It seems that the ones you get autogenerated are. However, IIRC any of
glob reference, glob itself, or reference to a PVIO are equally valid in
most everywhere that takes a "file handle". PVIOs are a bit awkward to get
a reference to. The only way I know is via thingy syntax on globs:

$ perl -MDevel::Peek -e 'Dump *STDOUT{IO}'
SV = RV(0x817e18) at 0x800168
  REFCNT = 1
  FLAGS = (TEMP,ROK)
  RV = 0x800888
  SV = PVIO(0x203ed0) at 0x800888
    REFCNT = 3
    FLAGS = (OBJECT)
    IV = 0
    NV = 0
    STASH = 0x80084c    "IO::Handle"
    IFP = 0x201c08
    OFP = 0x201c08
    DIRP = 0x0
    LINES = 0
    PAGE = 0
    PAGE_LEN = 60
    LINES_LEFT = 0
    TOP_GV = 0x0
    FMT_GV = 0x0
    BOTTOM_GV = 0x0
    SUBPROCESS = 0
    TYPE = '>'
    FLAGS = 0x0


> of the GLOB ref. Perhaps just use the {SCALAR} part of it for the name?

This is what I did. Thanks to everyone who suggested it.

http://public.activestate.com/cgi-bin/perlbrowse/p/33539

Nicholas Clark


More information about the london.pm mailing list