in reply to Splitting string based on potentially escaped character

You could use a compiled regexp:

perl -E ' my $x = "foo+bar+baz"; my $y = "+"; my $z = qr/\Q$y\E/; say for split $z, $x; '
Output:
foo bar baz
... but why not just use:
say for split /\Q$y\E/, $x;
in all cases? (There's probably a reason; I don't know it.)

Hope this helps!


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: Splitting string based on potentially escaped character
by clamport (Initiate) on Mar 07, 2017 at 18:52 UTC

    That's great, Thank you! I'm relatively new to perl so I must not have had the syntax correct when attempting to use the /Q/E. Much appreciated!