Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 476743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:31:14+00:00 2026-05-13T00:31:14+00:00

By default, perl prints \r\n in a win32 environment. How can I override this?

  • 0

By default, perl prints \r\n in a win32 environment. How can I override this? I’m using perl to make some changes to some source code in a repository, and I don’t want to change all the newline characters.

I tried changing the output record separator but with no luck.

Thanks!

Edit: Wanted to include a code sample – I’m doing a search and replace over some files that follow a relatively straightforward pattern like this:

#!/usr/bin/perl
# test.pl

use strict;
use warnings;

$/ = undef;
$\ = "\n"; 
$^I=".old~";

while (<>) {
  while (s/hello/world/) {

  }
  print;
}

This should replace any instances of “hello” with “world” for any files passed on the cmd line.

Edit 2: I tried the binmode as suggested without any luck initially. I delved a bit more and found that $^I (the inplace edit special variable) was overriding binmode. Any work around to still be able to use the inplace edit?

Edit 3: As Sinan points out below, I needed to use binmode ARGVOUT with $^I instead of binmode STDOUT in my example. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T00:31:14+00:00Added an answer on May 13, 2026 at 12:31 am

    Printing "\n" to a filehandle on Windows emits, by default, a CARRIAGE RETURN ("\015") followed by a LINE FEED ("\012") character because that the standard newline sequence on Windows.

    This happens transparently, so you need to override it for the special filehandle ARGVOUT (see perldoc perlvar):

    #!/usr/bin/perl -i.bak
    
    use strict; use warnings;
    
    local ($\, $/);
    
    while (<>) {
        binmode ARGVOUT;
        print;
    }
    

    Output:

    C:\Temp> xxd test.txt
    0000000: 7465 7374 0d0a 0d0a                      test....
    
    C:\Temp> h test.txt
    
    C:\Temp> xxd test.txt
    0000000: 7465 7374 0a0a                           test..
    

    See also perldoc open, perldoc binmode and perldoc perliol (thanks daotoad).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

By default, the ordered list looks like this: There are some spacing on the
Edited Now my code is like this: #!/usr/bin/perl # import packages use Net::POP3; use
I am using the Win32::OLE Perl module to change the pattern for a particular
I'm checking for the existence and default values of various socket options using Perl.
I have some reasonable (not obfuscated) Perl source files, and I need a tokenizer,
According the Perl documentation on regexes : By default, the "^" character is guaranteed
The default markdown syntax for code blocks is indented by 4 spaces on each
By default, an unstyled set of nested <ul> lists looks like this (in Chrome,
I have created a package using PackageMaker and want to change the default icon
The following Perl script outputs SUCCESS as you'd expect: use Fcntl qw(:DEFAULT :flock); sysopen(LF,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.