Unquoting Your Hash Keys · Jan 9, 12:07 PM by Dylan Doxey
I once thought it was pretty neat to format my hash keys like this.
1 use strict;
2 use warnings;
3
4 my $day = $date_rh->{ 'day' };
5 my $month = $date_rh->{ 'month' };
6 my $year = $date_rh->{ 'year' };
7
I have now flipped from that flop.
Here's how I like to see my keys formatted now.
1 use strict;
2 use warnings;
3
4 my $day = $date_rh->{day};
5 my $month = $date_rh->{month};
6 my $year = $date_rh->{year};
7
Now whenever I open up a program and start making tweaks one of the first things to go is the old line bloating style of hash keys.
However, this is an excersize in tedium when one is not adept with vim pattern matching.
So here's a tip.
:%s/{[ ]*'\([A-Za-z0-9_]\+\)'[ ]*}/{\1}/g
The key with this pattern is knowing what to escape with the backslash. Here you can see that the pattern meta-characters are backslashed.
Enjoy.

Commenting is closed for this article.
Ubuntu Release Upgrade Making Stuff Faster -- MySQL to be Specific
