Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

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

by choroba (Archbishop)
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 (Canon) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1143109]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2022-01-26 16:28 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (69 votes). Check out past polls.