in reply to Code for elegance, code for clarity
Yes, I know I like whitespace (look at that cascading unless).sub csv_split { local $_ = shift || return undef; my @array; my $count = my $quoted = 0; while ( s/(.)// ) { if ( $1 eq ',' and !$quoted ) { $count++; } elsif( $1 eq q/"/ ) { $quoted = 1 - $quoted unless $quoted and s/^\"//; } else { $array[$count] .= $1; } } return @array; }
I also wouldn't bother to write && except when needed (nothing wrong with and)
update: also, when all you want is to match, use m//.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Code for elegance, code for clarity
by Roy Johnson (Monsignor) on Jan 12, 2004 at 16:22 UTC | |
Re: Re: Code for elegance, code for clarity
by delirium (Chaplain) on Jan 12, 2004 at 14:45 UTC | |
Re: Re: Code for elegance, code for clarity
by duff (Parson) on Jan 12, 2004 at 14:51 UTC |