clamport has asked for the wisdom of the Perl Monks concerning the following question:
Hello all, long time lurker first time poster. I've been working on a script and I have a function that _should_ allow me to split based on a separator character.
I am currently attempting to figure out how to get the split to work correctly if the separator is a special escape character. I've tried the following methods. My goal is to get the given character replaced with a new substring '<SEP_CHAR>' which is assigned to $SEP_CHAR.
and$character = "/\Q$character\E/" if $character eq '+'; my $stringToProcess = join($SEP_CHAR, split($character, $string));
$character = "\\\$character" if $character eq '+'; my $stringToProcess = join($SEP_CHAR, split($character, $string));
Does anyone have any recommendations?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Splitting string based on potentially escaped character
by kennethk (Abbot) on Mar 07, 2017 at 18:53 UTC | |
|
Re: Splitting string based on potentially escaped character
by AnomalousMonk (Archbishop) on Mar 07, 2017 at 19:02 UTC | |
by Anonymous Monk on Mar 07, 2017 at 19:10 UTC | |
|
Re: Splitting string based on potentially escaped character
by kcott (Archbishop) on Mar 08, 2017 at 06:56 UTC | |
|
Re: Splitting string based on potentially escaped character
by 1nickt (Canon) on Mar 07, 2017 at 18:47 UTC | |
by clamport (Initiate) on Mar 07, 2017 at 18:52 UTC |