Bennett Haselton wrote:
> 
> This code:
> >>>
> my $ref = {'eggs' => 'bacon'};
> print $ref->{eggs}, "\n";
> print $ref, "\n"; # prints $ref as a hex number
> print ($ref)->{eggs}, "aaaaaaaaaa\n"; # also prints $ref as hex number (why?)
> >>>
> 
> outputs:
> >>>
> bacon
> HASH(0x176f054)
> HASH(0x176f054)
> >>>
> 
> on both perl 5.005_03 for UNIX, and ActivePerl 5.6.0 build 623.
> 
> Am I reading it wrong?  It seems like
> $ref->{eggs}
> and
> ($ref)->{eggs}
> ought to look the same when printed, but they don't.  "->" requires a left
> operand, so it ought to remove any ambiguity about what the line means.
> 
> There are times when you'd need the latter form, such as when a reference
> is obtained by a function call, as in this code:
> 
> >>>
> sub ReturnRef
> {
>         my $ref = {};
>         $ref->{eggs} = 'bacon';
>         return $ref;
> }
> print (ReturnRef)->{eggs};
> >>>
> which looks to me like it ought to print "bacon", but actually prints
> HASH(0x176f054).
> 
> You *can* do the following:
> >>>
> sub ReturnRef
> {
>         my $ref = {};
>         $ref->{eggs} = 'bacon';
>         return $ref;
> }
> print ((ReturnRef)->{eggs});
> >>>
> and this will print "bacon" instead of "HASH(0x176f054)", since apparently
> the parentheses around "(ReturnRef)->{eggs}" make it work.  But it doesn't
> seem like they should be necessary.
> 
> And in any case, how come
> print ($ref)->{eggs}, "aaaaaaaaaa\n";
> doesn't print out the "aaaaaaaaaa\n" at the end, just the hex hash value?
> 
> Is this a specific case of some general source of confusion that is
> addressed in a FAQ?

The hex value is the is I believe the symbol table location of the vrbl.
You need to de-reference it.

>From perlreftut docs:

    *   If you try to use a reference like a string, you get strings like

                ARRAY(0x80f5dec)   or    HASH(0x826afc0)

        If you ever see a string that looks like this, you'll know you
        printed out a reference by mistake.

-- 
  ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
 (_/   /  )    // //       DBE Collectibles   http://www.todbe.com/
  / ) /--<  o // //      Mailto:[EMAIL PROTECTED] http://dbecoll.webjump.com/
-/-' /___/_<_</_</_    http://www.freeyellow.com/members/dbecoll/
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users

Reply via email to