John, how about:

(@fields) = split /(\||\^)/,$record;


I know it looks like line noise, that's a pipe (escaped) a pipe (as the logical OR) and a caret (escaped)


Pipe and caret have special meanings in regex, so they have to be handled specially.

John V. Pataki wrote:
I use a variable for a field delimiter when reading
CSV files... I have been wrestling with the best way
to code my split regex so that it works with all
possible values of that variable. It is currently failing when I set the value of the
variable to ^



# if delimiter is | - this syntax works fine

$del=|
(@fields) = split /[$del]/,$record;


# if delimiter is ^ - this syntax fails - no split $del=^ (@fields) = split /[$del]/,$record;


What syntax will work for both (all) cases?

Thanks,

John




===== John V. Pataki Logged in to my Yahoo Mail account on the web.

_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to