[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Omaha.pm] Using -> inside double quotes



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