http://qs321.pair.com?node_id=656824

Dial your perldoc to perlsyn:

Here's how a C programmer might code up a particular algorithm in Perl: for (my $i = 0; $i < @ary1; $i++) { for (my $j = 0; $j < @ary2; $j++) { if ($ary1[$i] > $ary2[$j]) { last; # can't go to outer :-( } $ary1[$i] += $ary2[$j]; } # this is where that last takes me } Whereas here's how a Perl programmer more comfortable with the idiom might do it: OUTER: for my $wid (@ary1) { INNER: for my $jet (@ary2) { next OUTER if $wid > $jet; $wid += $jet; } }

When I scanned the above yesterday, I realized that there is a lot of C in my Perl. I, without a doubt, would have rolled the C loop to solve that problem. I don't want to focus too much on that example, though, it's just the catalyst that made me start thinking about this.

It's all over my code, I'll roll a C-style loop where a map would fit better, I'll go for the C solution rather than use better suited Perl idioms. Sometimes I'll notice this after the fact and write it better, sometimes I won't. But what really worries me is that I'm not really getting better at it over time. Sure, I know more about Perl and have a handle on more advanced features now, but I'm not really writing much better code than I did 5 years ago. Maybe it's because Perl isn't my main breadwinner, maybe I'm just stubborn.

Can you teach an old dog new tricks? Or rather, can you point me towards any kind of resource that would help? Or talk about your own experiences, or anything else you think would be useful.

For reference, the things that have made me "okay" at writing Perl so far are:

And that's that. Oh, also I put this in Meditations rather than Seekers because it seemed like the place for this kind of open-ended discussion-ish question, but I can axe it and move it if people want.

Edit: (Dec 14, 2007 at 15:40ish UTC): Thank you all for so much advice in such a short time. I think my plan going forward would be to:

  1. Learn a language that slaps me in the face with its functional nature, to expand my problem-solving toolbox.
  2. Try to spend more time with "Here's a problem - Here's a Perl solution" articles and such. The Cookbook has been good to me, so I might as well run with that kind of resource.
  3. Try to be less gunshy about asking questions here.

As to why I want to change, I currently write "okay" code with "okay" maintainability when working with Perl. I suppose I'm sort of annoyed that tool I'm happiest with is the one I produce the worst product with.