in reply to Re^3: Substitution in range operator
in thread Substitution in range operator

Output:

foo | bar baz qux fred wilma barney

Perl -v perl 5, version 14 subversion 2 (v5.14.2) built for cygwin-thread-multi-64int

Replies are listed 'Best First'.
Re^5: Substitution in range operator
by ww (Archbishop) on Dec 30, 2015 at 11:27 UTC
Re^5: Substitution in range operator
by 1nickt (Canon) on Dec 30, 2015 at 06:51 UTC

    I'm not sure if it is an issue with the Perl version (I am using 5.16.3 and 5.22), but rather with line endings on Windows. I don't use Windows myself, but there are considerations with line-endings on that platform; do a search and you'll find at least a couple of discussions about the topic in the last couple of months.

    What happens if you change the key line to:

    $txt =~ s/\r\n\|/ /g;
    ?


    The way forward always starts with a minimal test.

      I get the correct output but in my script it doesn't change the pipe or remove the new line. Funny because i copied the char into a hex editor and got "a" (new line not carriage return) I'll play around with it some more tomorrow but is there a way to use hex values in the regex? - just googled http://www.regular-expressions.info/nonprint.html so I'll have another look at a hex editor tomorrow and give it a go trying with hex symbols.

      foo | bar baz qux fred wilma barney

        I don't think I can use hex values in regex the hex is "a7c"

      I get the correct output but in my script it doesn't change the pipe or remove the new line. Funny because i copied the char into a hex editor and got "a" (new line not carriage return) I'll play around with it some more tomorrow but is there a way to use hex values in the regex? - just googled http://www.regular-expressions.info/nonprint.html so I'll have another look at a hex editor tomorrow and give it a go trying with hex symbols.

      foo | bar baz qux fred wilma barney