Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Beatnik (493)

  (email not shown publicly)

A 29 year old belgian who likes Mountain Dew, Girl Scout Cookies, Tim Hortons French Vanilla Flavoured Cappucinno, Belgian beer, Belgian chocolate, Belgian women, Magners Cider, chocolate chipped cookies and Perl. Likes snowboarding, snorkling, sailing and silence. Bach can really cheer him up! He still misses his dog.

Project Daddy of Spine [], a mod_perl based CMS.

In his superhero time (8.30 AM to 5.30 PM), he works on world peace.

Journal of Beatnik (493)

Tuesday June 06, 2006
10:49 AM

Perl style

[ #29824 ]
How I love those moments where I can baffle one of the senior techies by giving some perl pointers. Just now, I had my 5 minutes of gloating. The problem: Add a catch-all string into the following snippet:

$foo = $bar unless $foo;

My solution was something like:

$foo ||= $bar || "Catch";

I tried explaining this by using both

$result = open(FOO,"<..") || "Oops";


$a = $a + 1; versus $a += $1;

It slowly sunk in. The unless bit reminded me of a section in the Perl Best Practices book I'm reading. Thanks Damian! I pointed out some extra funny bits by bringing in the C-style short hand for if-then-else. Maybe I was doing this to get a 5 minute break from work..

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • I would be rather perturbed to find that in production code without explicit comments that values such as

    reference to an empty hash, array, or any of the above

    for $foo and $bar are invalid and assigning over them is safe
    • Obviously, $foo is not in production code :) but the style is.
    • why?

      Why should any of those be valid apart from 0.

      If you can't see the type and usage of a variable, the solution is to name it correctly.

      It should also be clear if 0 is acceptable or not in the code, that would be the only comment possibly needed.

      @JAPH = qw(Hacker Perl Another Just);
      print reverse @JAPH;