> -----Message d'origine----- > De : KEVIN ZEMBOWER [mailto:[EMAIL PROTECTED] > Envoyé : lundi 28 mars 2005 18:13 > À : beginners@perl.org > Objet : Problems matching or parsing with delimiters in text > > I'm trying to read in text lines from a file that look like this: > "B-B01","Eng","Binder for Complete Set of Population Reports",13,0 > "C-CD01","Eng","The Condoms CD-ROM",12,1 > "F-J41a","Fre",,13,1 > "F-J41a","SPA",,13,1 > "M-FC01","Eng","Africa Flip Charts- Planning Your Family (E,F, > Swahili)(12""x9"")",7,1 > "M-FC01","Fre","Africa Flip Charts- Planning Your Family (E,F, > Swahili)(12""x9"")",7,1 > > The first two lines are typical of most of the file. The second two have a > blank third field and the last two show embedded commas and escaped double > quotes in the third field. This is an output of another program, but I can > filter it and make substitutions if that makes anything easier. > > I'm trying to parse it with these statements: > while (<>) { # While there are more records in the inventory export file
I heven't read the complete post but ;) your file seems to have a well known format called CSV (Comma Separated Value). You don't need to reinvent the wheel writing yourself a parser for such files, since proven solutions (modules) already exist doing it for you. Have a look to CPAN (http://search.cpan.org) search for Text::CVS. Text::CVS::Simple seems interesting http://search.cpan.org/~tmtm/Text-CSV-Simple-0.20/ Install and try ... HTH, José. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>