To: "Jean-Louis" <[EMAIL PROTECTED]> Subject: Re: help on how to split a string References: <003701c1909a$e125aab0$74d2fea9@JEANLOUIS> --text follows this line-- "Jean-Louis" <[EMAIL PROTECTED]> writes: > I found that $l=readline($filehandle) gives me the content of the current line. Use these instead.
$line = <FILEHANDLE>; chomp $line; or $line = <>; chomp $line; > Now, how can I explode the line. I'd like: > $val[0]="a", $val[1]="bcd, efg, h", $val[2]="c" (or equivalent). > > I cannot figure out how to use split when the delimiter is the double quote. Don't use split for CSV fields that may (or may not) have quotes. Although it may be tempting to use RE's, it's a lot harder than it may initially look. There's all kinds of special cases - backslashes preceeding a character, quotes within quotes, ... Try these modules from CPAN http://search.cpan.org/doc/HALPOM/Text-ParseWords-3.1/ParseWords.pm http://search.cpan.org/doc/ALANCITT/Text-CSV-0.01/CSV.pm I haven't used them, but I'm guessing that this will work: use Text::ParseWords; $line = '"a", "bcd, efg, h", "c"'; @words = parse_line(",", 0, $line); foreach (@words) { printf "%d. <%s>\n", $index++, $_; } Should print: 1. <a> 2. <bcd, efg, h> 3. <c> -- Michael R. Wolf All mammals learn by playing! [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]