Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: \R not working as (I) expect on Windows Strawberry perl

by choroba (Bishop)
on Sep 26, 2015 at 17:53 UTC ( #1143109=note: print w/replies, xml ) Need Help??

in reply to \R not working as (I'd have) expected on Windows Strawberry perl

On MSWin, all filehandles are opened with the :crlf layer by default. Therefore, the $_ coming from <> doesn't contain the \x0d anymore. To get the Unix behaviour, do
binmode FH, ':raw';

Update: I wasn't able to make this work with -n and filename argument - somehow, you have to change the bimode of an open filehandle, but -n opens it and reads from it at the same time or something (anyone?). Therefore, I had to write the loop myself:

perl -wE 'use open IN => ":raw"; while (<>) { /(\R)/; say (unpack "H*" +, $1); }' file

Update 2: -M works, thanks Anonymous Monk:

perl -Mopen=IN,:raw -wnE '/(\R)/; say unpack "H*", $1' file
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: \R not working as (I) expect on Windows Strawberry perl (binmode -l -n -p -e oneliner)
by Anonymous Monk on Sep 26, 2015 at 21:17 UTC
Re^2: \R not working as (I) expect on Windows Strawberry perl
by stevieb (Abbot) on Sep 26, 2015 at 18:00 UTC

    Thanks choroba, that indeed fixed it. I'll have a good read of open and many things associated with it (such as filers) today.



Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1143109]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2018-07-23 02:47 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (459 votes). Check out past polls.