linux - Perl \R regex strip Windows newline character -
i'm using perl script using following code remove possible windows newline characters in input file:
foreach $line(split /\r|\r/)
executing same script on 2 different linux machines has different results. on machine1 script works intended, on machine2 every time capital "r" character found line split , result messed.
i know if \r regex correct , how make machine2 behave intended.
in perl, there several differences in way carriage returns can handled:
\n matches line-feed (newline) character (ascii 10) \r matches carriage return (ascii 13) \r matches unicode newline sequence; can modified using verbs windows uses 2 characters ascii 13+ascii 10 (\r\n) , unix uses ascii 10 (\n). \r expression matches unicode newline sequence (\r, \n, \r\n).
the reason \r works on 1 machine , not other might differing versions of perl. \r introduced in perl 5.10.0, if other machine using older version updating should solve issue.
more info:
Comments
Post a Comment