in reply to Perl regex txt file new line (not recognised?)

G'day thurinus,

Welcome to the Monastery.

As already indicated, it's likely you have line terminators not matching the '$'. You may have more success using '\R', the generic newline. See perlrebackslash: \R and note you'll need at least Perl v5.10 to use this.

Here's a quick-and-dirty example to compare '$' with '\R':

$ perl -E ' my @x = ( "A\n", "B.\n", "C\r", "D.\r", "E\r\n", "F.\r\n", "G\f", "H.\f" ); say q{*** With $ ***}; say "|$_|" for grep /\.$/, @x; say q{*** With \R ***}; say "|$_|" for grep /\.\R/, @x; ' *** With $ *** |B. | *** With \R *** |B. | |D. |F. | |H. |

In case you didn't know, the '\f' is a form-feed.

— Ken

Replies are listed 'Best First'.
Re^2: Perl regex txt file new line (not recognised?)
by Anonymous Monk on Jan 22, 2020 at 08:37 UTC

    Dear Monks,

    the line terminators were the issue and I could fix it with your help and suggestions.

    Thanks a lot for your help!