in reply to Help understanding a single line of perl: my $count = $row[0] ? $row[0] : 0;
One question that might occur to someone who is new to this construct is "Why use it in this case?"
Because an undefined value is false, this little snippet of code will make sure that count is always defined to a specific value, even if $row[0] is not defined. So if your @row was the result of some operation that happened to return an empty list, $count would set to 0 rather than '';
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Help understanding a single line of perl: my $count = $row[0] ? $row[0] : 0;
by ikegami (Patriarch) on Aug 21, 2009 at 19:37 UTC |
In Section
Seekers of Perl Wisdom