develooper Front page | perl.beginners | Postings from February 2002

RE: Parsing a .csv file

Thread Previous | Thread Next
From:
Richard Smith
Date:
February 12, 2002 06:30
Subject:
RE: Parsing a .csv file
Message ID:
01C1B3A8.0C3FF400.rsmith@datamarktech.com
You might try splitting on quotes first., e.g.
	my @quotes_array = spilt /"/, $input;
	my @final_array;
	# Array members with odd idices will be quoted strings, split others on comma.
	for ( my $index = 0; $index < @quotes; $index++ )
	{
		if ( $index % 2 )
		{
			push @final_array, ( split /,/, $quotes_array[ $index ] );
		}
		else
		{
			push @final_array, $quotes_array[ $index ]
		}
	}

Some one else may be able to think of a less "C"ish way...
Smiddy


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About