in reply to Re^4: creating hash of hashes from input file (OT: PBP)
in thread creating hash of hashes from input file

You chose a good example. I've always found it difficult to come up with any style of concatentation/interpolation that doesn't look cluttered and hard to read. A significant proportion of my bugs are due to this.

As soon as there is any amount of complexity I reach for builtins with parens.

my $str = sprintf( qq{(%s)\n}, join(q{,}, @things), );
Clearly, this is borderline complexity but I've had ternaries, function calls, math (generously seasoned with parens) and the kitchen sink in there as well. I find having a trailing paren to pin the ; to helps me keep things in order. In a word: templates++.

I was disappointed with the book and wish I had bought something else. A two page pdf trying to be a book. I've adopted q, qq, qw and qr but I'm not sure if that was due to advice or my code editor.

And while we're here, you can't have the words "readable" and "uncluttered" alongside the phrase "nested ternaries". However hard people try to format them they're unreadble. Too posh to use a humble if/elsif/else block?

Phew, that's better. :-)

Replies are listed 'Best First'.
Re^6: creating hash of hashes from input file (OT: PBP)
by FunkyMonk (Bishop) on Jul 18, 2010 at 21:59 UTC
    I was disappointed with the book and wish I had bought something else

    /me too

    I bought it, but I can't read more than a couple of pages without getting annoyed.

    you can't have the words "readable" and "uncluttered" alongside the phrase "nested ternaries".
    What wrong with

    my $baz = $foo == 1 ? 'red' : $foo == 2 ? 'blue' : $foo == 3 ? 'green' : 'yellow';

    I don't use it often, but I find it uncluttered and very readable.