Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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.

    Cheers,

    -stevieb

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1143109]
help
Chatterbox?
NodeReaper files his shovel

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2017-11-18 04:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (277 votes). Check out past polls.

    Notices?