when I'm parsing a csv file, and don't want to use those elements that
return a nil value, what is the easiest way to do so? I've tried:
if record == nil
next
else
where record is the current element from the file.
···
--
Posted via http://www.ruby-forum.com/.
Lars
(Lars)
2
If tend to like boolean expressions rather than comparison with
'nil' (or false):
next if record.nil?
or
next unless record
The latter will skip when next is either 'nil' or 'false'.
If you have multiple fields and want to skip if they all are nil/
false:
next unless first or second or third
If you want to skip if any of them are nil/false:
next unless first and second and third
Lars
···
On Mar 6, 6:24 pm, Max Russell <thedoss...@gmail.com> wrote:
when I'm parsing a csv file, and don't want to use those elements that
return a nil value, what is the easiest way to do so? I've tried:
if record == nil
next
else
Depending on what you are doing, you can parse first, use #compact after.
Todd
···
On Thu, Mar 6, 2008 at 11:24 AM, Max Russell <thedossone@gmail.com> wrote:
when I'm parsing a csv file, and don't want to use those elements that
return a nil value, what is the easiest way to do so? I've tried:
if record == nil
next
else
where record is the current element from the file.