Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delimiter delimma

Status
Not open for further replies.

new2unix

Programmer
Feb 5, 2001
143
0
0
US
Hi,

Have a source file containing this following sample text:

ID|PATTERN1|USER1
ID|PATTERN1\|PATTERN2|USER2
ID|PATTERN1\|PATTERN2\|PATTERN3|USER3
ID|PATTERN4|USER1
.....
.....

Each line actually has only 3 fiedls delimited by "|". But the problem is the possible combination of "\|" that may occur inside the second field. Not sure how I might use the split or other function to deal with the "\|" to split the data into:

$field1 = text in ID field
$field2 = text representing PATTERN1\|PATTERN2\|.... etc
$field3 = text in USER field


Thanks,

Mike
 
use split function.

then, loop through the results and if an element has "\" as its last character, join it with the next element of the array.
 
You can just do it with split, in fact.
Code:
@fields = split /(?<!\\)\|/, $line;

That regex matches any | character that is not preceded by a \.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top