[Omaha.pm] Using -> inside double quotes

Jay Hannah jay at jays.net
Thu Aug 14 07:02:16 PDT 2008


Funny how you can use -> inside double quotes to get at a hashref  
value, but you can't use it to invoke an object method.


$ cat j2.pl
package Jay;
sub new { bless {} }
sub lastname { "Hannah" }

package main;
my $href = {
    7 => 'seven'
};
my $jay = Jay->new();
print "$href->{7} $jay->lastname\n";

$ perl j2.pl
seven Jay=HASH(0x8170b44)->lastname


I guess that confusion is what taught me, years ago, to never use ->  
inside double quotes. Until today, when I hit someone's code doing it.

Huh. I'm still learning perl5.  :)

j




More information about the Omaha-pm mailing list