Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am debugging a large program I didn't write. At some point in the code, it prints GLOB(0xstuff) a bunch of times. The stuff is a hex number, presumably a mem address on my computer.

I am wondering what kind of structure one has to print in order to get this result. I tried printing references without dereferencing them, but that gets me HASH(0xstuff) ARRAY(0xstuff) and SCALAR(0xstuff), depending on what kind of reference I use.

I am running 5.8.1 on Redhat 9, though the code was originally written under 5.6.x on Redhat 7.3.

Please give me a hint, like some sample code that prints this type of output, or refer me to the correct section of TFM (I couldn't find it in perldoc).

  • Comment on What kind of code prints GLOB(hexaddress)

Replies are listed 'Best First'.
Re: What kind of code prints GLOB(hexaddress)
by Paladin (Vicar) on Jun 06, 2003 at 19:43 UTC
    A reference to a glob prints that. ie:
    [~]$ perl -le '$var = \*FOO; print $var;' GLOB(0x805f888)
    One of the more common uses of globrefs are passing file handles into and out of subs, although this is less common now with the IO:: modules.

      Thanks a lot! Your suggestion about filehandles was right on. I had converted one of the globs to a variable to get syntax highlighting on it and the new code had something like:
      while(<FOO>){print $BAR;}
      This doesn't default to filehandle semantics, so you get the GLOB thing.

Re: What kind of code prints GLOB(hexaddress)
by DigitalKitty (Parson) on Jun 06, 2003 at 20:18 UTC
    Hi Anonymous Monk.

    I can understand how you feel. I have 'inherited' code written by co-workers ( past and present ) and the quality isn't always 'stellar' ( no documentation, large program with very few subroutines, etc. ).

    #!/usr/bin/perl use strict; my @array = qw( perl is very cool ); my %hash = ( perl => "coder" ); print "\@array = ", ref( \@array ), "\n"; print "\%hash = ", ref( \%hash ), "\n"; print "\&subroutine = ", ref( \&subroutine ), "\n"; print "\*array = ", ref( \*array ), "\n"; sub subroutine { print "I'm a perl coder!\n"; }

    Output:
    @array = ARRAY %hash = HASH &subroutine = CODE *array = GLOB

    The ref() function receives a reference argument and returns a string describing the type of reference passed to it. You are correct in assuming the hex number is a memory address. In 'C', this is essential when working with pointers but perl's use of references is safer and possesses improved stability.

    Hope this helps,
    -Katie.