Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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

by choroba (Cardinal)
on Sep 26, 2015 at 17:53 UTC ( [id://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.

    Cheers,

    -stevieb

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1143109]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2024-03-19 02:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found