in reply to Help understanding a single line of perl: my $count = $row[0] ? $row[0] : 0;
is similar tocond ? then_expr : else_expr
if (cond) { then_expr } else { else_expr }
except it can be used inside another expression. It returns the value of then_expr or else_expr as appropriate. That means
is short formy $count = $row[0] ? $row[0] : 0;
my $count; if ($row[0]) { $count = $row[0]; } else { $count = 0; }
Update:
It could also have been written as
my $count = $row[0] || 0;
It seems to me it's trying to avoid assigning undef to $count, using zero instead when the situation occurs.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Help understanding a single line of perl: my $count = $row[0] ? $row[0] : 0;
by Tanktalus (Canon) on Aug 21, 2009 at 18:50 UTC | |
by ikegami (Patriarch) on Aug 21, 2009 at 18:57 UTC | |
|
Re^2: Help understanding a single line of perl: my $count = $row[0] ? $row[0] : 0;
by kdmurphy001 (Sexton) on Aug 21, 2009 at 18:59 UTC |