fun with perl

Friday, May 17, 2002, at 08:21PM

By Eric Richardson

So right now I'm reading through Damian Conway's Object Oriented Perl, and I'm learning some cool little syntax stuff I didn't know. I'm sure most of you don't care, so I'll put it in the post body. Click to read more...

The first thing I didn't realize was that ${$foo}{bar} and $foo->{bar} were equivalent. That's very cool. Much more readable. So instead of junk like:


I can have:


Sure, the change is subtle, but I think it's really nice.

Similarly, I found a bit about hash assignment really interesting. For instance, I have lots of bits of code where I do:

%{$foo{bar}} = (a=>1,b=>2);

A much cleaner way to write this would be:

$foo{bar} = {a=>1,b=>2};

Or, to combine the two together, I can go from:

%{$e{buttons}{${$b}[0]}} = (name=>${$b}[0],link=>${$b}[1]);


$e{buttons}{$b->[0]} = {name=>$b->[0],link=>$b->[1]};

Ahhh.... Readability...