develooper Front page | perl.perl5.porters | Postings from August 2001

Can't localize *FH, then tie it

Thread Next
Ken Williams
August 1, 2001 22:04
Can't localize *FH, then tie it
Message ID:

I just ran the following test program under 5.6.1:

#!/usr/bin/perl -l

    local *foo;
    tie %foo, 'Blah';
print tied %foo ? 'not ok 1' : 'ok 1';

    local *bar;
    tie @bar, 'Blah';
print tied @bar ? 'not ok 2' : 'ok 2';

    local *BAZ;
    tie *BAZ, 'Blah';
print tied *BAZ ? 'not ok 3' : 'ok 3';

package Blah;
sub TIEHANDLE {bless {}}
sub TIEHASH   {bless {}}
sub TIEARRAY  {bless {}}

The output is:
  ok 1
  ok 2
  not ok 3

It seems like there's no way to let a filehandle revert to its former
state after exiting the block in which it was tied, though this can be
done with other data types.  I consider it a bug, what do others think?  

The only semi-relevant entry in was this one:
Please point me to TFM if necessary.

Perhaps needless to say, I want to do this so that I can tie STDOUT in a
certain scope without clobbering a previous tie.

Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration:
    osname=darwin, osvers=1.3.7, archname=darwin
    uname='darwin localhost 1.3.7 darwin kernel version 1.3.7: sat jun 9
11:12:48 pdt 2001; root:xnuxnu-124.13.obj~1release_ppc power macintosh powerpc
    config_args='-des -Dfirstmakefile=GNUmakefile'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef
    useperlio=undef d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    cc='cc', ccflags ='-pipe -fno-common -DHAS_TELLDIR_PROTOTYPE
-fno-strict-aliasing -I/usr/local/include',
    cppflags='-pipe -fno-common -DHAS_TELLDIR_PROTOTYPE -fno-strict-aliasing
    ccversion='', gccversion='Apple DevKit-based CPP 6.0alpha', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
    alignbytes=8, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib
    libs=-lm -lc
    perllibs=-lm -lc
    libc=/System/Library/Frameworks/System.framework/System, so=dylib,
useshrplib=true, libperl=libperl.dylib
  Dynamic Linking:
    dlsrc=dl_dyld.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags=' -bundle -undefined suppress -L/usr/local/lib'

Characteristics of this binary (from libperl): 
  Compile-time options: USE_LARGE_FILES
  Built under darwin
  Compiled at 07/18/01 21:47:28

  -------------------                            -------------------
  Ken Williams                             Last Bastion of Euclidity                            The Math Forum

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About