May
18

fun with perl

Published: Saturday, May 18, 2002, at 12:21AM

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:


$e{buttons}{${$b}[0]}


I can have:


$e{buttons}{$b->[0]}


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]);


to:


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


Ahhh.... Readability...

Comments

No comments yet.

Your Comment:

YOUR INFORMATION:
Name:
Email:
URL:
  • Comments should be on the topic of the post or they will be removed.
  • Use the live preview below to see how your comment will look before posting.
  • Keep it civil. If you're attacking people instead of arguments, or being overly profane, expect your comment to get deleted.

FORMATTING BASICS:

eWorld uses Markdown formatting.

_Italics_
__Bold__
<http://url.to.link>
[link text](http://url)

COMMENT:

Preview

Start typing...