| Jose Nyimi 2005-03-28, 3:56 pm |
|
> -----Message d'origine-----
> De=A0: KEVIN ZEMBOWER [mailto:KZEMBOWE@jhuccp.org]
> Envoy=E9=A0: lundi 28 mars 2005 18:13
> =C0=A0: beginners@perl.org
> Objet=A0: Problems matching or parsing with delimiters in text
>=20
> 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
>=20
> 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.
>=20
> 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=20
http://search.cpan.org/~tmtm/Text-CSV-Simple-0.20/
Install and try ...
HTH,
Jos=E9.
|