I'm struggling with a tricky quoting problem:

I need to split lines divided by some delimiter;

- The delimiter usually will be '|',
  but can be changed, so it needs to be variable.
- Furthermore, the columns may also contain the delimiter,
  in which case it is quoted by a backslash

No problem, as long as I know the delimiter in advance:

my $split_rx= qr[(?<!\\)\|];
my (@cols)= split $split_rx, $line;

But with the delimiter contained in a variable,
no matter what I try, I just can't get an equivalent regex:

my $delimiter='|';

  $split_rx= qr[(?<!\\)\$delimiter];
  # the '$' is quoted, so the variable won't be expanded;

  $split_rx= qr[(?<!\\)\\$delimiter];
  # now the backslash is is quoted instead

I also tried variations using quotemeta or the 'x' modifier,
but I just don't get it right :-(

Any ideas?

                       Regards,
                                           Peter


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to