in reply to Re: Help understanding a single line of perl: my $count = $row[0] ? $row[0] : 0;
in thread Help understanding a single line of perl: my $count = $row[0] ? $row[0] : 0;

Well, it's probably closer to:

my $count = do { if ($row[0]) { $row[0]; } else { 0 } };
but that's less readable to the uninitiated than what you have. :-P

  • Comment on Re^2: Help understanding a single line of perl: my $count = $row[0] ? $row[0] : 0;
  • Download Code

Replies are listed 'Best First'.
Re^3: Help understanding a single line of perl: my $count = $row[0] ? $row[0] : 0;
by ikegami (Patriarch) on Aug 21, 2009 at 18:57 UTC
    if already returns the right thing. It's simply a parser check that prevents it from being used as an expression. (But I guess you know that.)

    I would have used do if it would have made it equivalent, but since it didn't, it was more readable to explain do rather than using do.