V
Vaughn Sargent
Hi,
I have some flat file data coming in from a client that is ~
delimited. I have no control over the incoming data so I'm stuck with
the ~. What I need to do is split the data into fields (which should
be easy using split) however, some text fields may contain a ~ but
it's not the delimiter, it's just part of the text field. All text
fields are enclosed with double quotes. Number and date fields are
not. So I may recieve data such as the following 5 field line:
"Field - One"~234.00~"Field ~ 3"~20040830~"Field 5"
What I want returned is:
Field 1: "Field - One"
Field 2: 234.00
Field 3: "Field ~ 3"
Field 4: 20040830
Field 5: "Field 5"
But using split perl returns:
Field 1: "Field - One"
Field 2: 234.00
Field 3: "Field
Field 4: 3"
Field 5: 20040830
Field 6: "Field 5"
It would also be possible for any text field to contain more than one
~ as a non-delimiter which may or may not be next to each other.
I guess what I would like to tell perl is "Hey, Perl, split this line
for me using ~ as the delimiter but ~ isn't a delimiter if there are
double quotes around it."
I thought it might be possible to use split and tack on a regular
expression. I'm a newbie when it comes to regular expressions.
If anyone can help me out I'd be very greatful.
Vaughn
I have some flat file data coming in from a client that is ~
delimited. I have no control over the incoming data so I'm stuck with
the ~. What I need to do is split the data into fields (which should
be easy using split) however, some text fields may contain a ~ but
it's not the delimiter, it's just part of the text field. All text
fields are enclosed with double quotes. Number and date fields are
not. So I may recieve data such as the following 5 field line:
"Field - One"~234.00~"Field ~ 3"~20040830~"Field 5"
What I want returned is:
Field 1: "Field - One"
Field 2: 234.00
Field 3: "Field ~ 3"
Field 4: 20040830
Field 5: "Field 5"
But using split perl returns:
Field 1: "Field - One"
Field 2: 234.00
Field 3: "Field
Field 4: 3"
Field 5: 20040830
Field 6: "Field 5"
It would also be possible for any text field to contain more than one
~ as a non-delimiter which may or may not be next to each other.
I guess what I would like to tell perl is "Hey, Perl, split this line
for me using ~ as the delimiter but ~ isn't a delimiter if there are
double quotes around it."
I thought it might be possible to use split and tack on a regular
expression. I'm a newbie when it comes to regular expressions.
If anyone can help me out I'd be very greatful.
Vaughn