Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Globref locally assigned to glob in method doesn't work #1087

p5pRT opened this issue Jan 25, 2000 · 5 comments

Globref locally assigned to glob in method doesn't work #1087

p5pRT opened this issue Jan 25, 2000 · 5 comments


Copy link

p5pRT commented Jan 25, 2000

Migrated from (status was 'resolved')

Searchable as RT2040$

Copy link

p5pRT commented Jan 25, 2000

From @mjdominus

I have a trivial module, It has two methods. The constructor
accepts a globref and creates an object that contains the globref as
member data. The other tries to read a line of data from the
filehandle associated with the globref. However, the data is not

Here is file '/tmp/t1', my test script​:

use Mod;
open TF, "< /tmp/t1" or die;
my $o = Mod->new(FH => \*TF);
my $data = $o->readit;
print $data;


Here is file '/tmp/', the module​:


package Mod;

sub new {
  my ($pkg, $fh) = @​_;
  my $self = {FH => $fh};
  bless $self => $pkg;

sub readit {
  my $self = shift;
  local *FH = $self->{FH};
  my $str = <FH>;
  return $str;



When I run the program /tmp/t1, I expect it to print out
its own first line​:

  use Mod;

instead, it prints nothing.

Perl Info

Site configuration information for perl 5.00503:

Configured by mjd at Sun Jan 23 14:15:22 EST 2000.

Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration:
    osname=linux, osvers=2.2.12, archname=i586-linux
    uname='linux plover 2.2.12 #10 mon nov 1 17:02:09 est 1999 i586 unknown '
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef useperlio=undef d_sfio=undef
    cc='cc', optimize='-O2', gccversion=egcs-2.90.29 980515 (egcs-1.0.3 release)
    cppflags='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    ccflags ='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    stdchar='char', d_stdstdio=define, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /shlib /lib /usr/lib
    libs=-lndbm -lgdbm -ldbm -ldb -ldl -lm -lc
    libc=/lib/, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:

@INC for perl 5.00503:

Environment for perl 5.00503:
    LANG (unset)
    LANGUAGE (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)

Copy link

p5pRT commented Jan 25, 2000

From @mjdominus

my $o = Mod->new(FH => \*TF);
my ($pkg, $fh) = @​_;

Gee, that was pretty stupid.

There really is a bug somewhere, but this doesn't demonstrate it.

I'll try again in the morning.

Copy link

p5pRT commented Jan 26, 2000

From [Unknown Contact. See original ticket]

If you change your call from

  my $o = Mod->new(FH => \*TF);


  my $o = Mod->new(\*TF);

it works fine. It also works fine if you make it

  my $o = Mod->new(*TF);

I don't know why

  *X = *FH
  *X = \*FH

are the same, although I do know why

  *X = "FH"

is the same, because it actually means *X = *{"FH"}. Apparently,
*X = \*FH really means *X = *{ \*FH }. I'd say this breaks the
no implicit dereffing rule, but with stars, all bets are off.

Also, you wouldn't need the local *FH if you just called


since readline() is a proper function not subject to the
sillinesses stopping < $self->{FH} > from working.

But I don't know if readline got fixed yet so it accepts
other than *FH. It should also accept anything <> does,
like FH and \*FH.


Copy link

p5pRT commented Jul 13, 2003

From @rspier

chromatic says​:
Bug #2040 looks like it can be closed; the constructor was called
incorrectly in the test case, as Tom's comment points out.

Copy link

p5pRT commented Jul 13, 2003

@rspier - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

1 participant