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

  • Home
  • SEARCH
  • 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 408445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:41:34+00:00 2026-05-12T17:41:34+00:00

I’m running Windows XP, Eclipse 3.2 with EPIC and Cygwin for my Perl interpreter, and

  • 0

I’m running Windows XP, Eclipse 3.2 with EPIC and Cygwin for my Perl interpreter, and I get an unexpected result.

FYI… When I run it on my Ubuntu distribution (VMware, same pc) I get the expected results. Why?

############ CODE: #############

use warnings;
use strict;

my $test = "test";
my $input = <STDIN>;

print length $test, " ", length $input, "\n";

chomp $input;

print "|$test| |$input| \n";    #The bars indicate white space, new line, etc...

print length $test, " ", length $input, "\n";

if ($test eq $input) {
    print "TIME TO QUIT";
}

Results on Windows XP:

test           <-- My input
4 6            <-- Lengths printed before chomp
|test| |test   <-- Print the variables after chomp
|              <-- There is still a new line there
4 5            <-- Lengths after the initial chomp
  • 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-12T17:41:34+00:00Added an answer on May 12, 2026 at 5:41 pm

    Based on the lengths, I’d say you’re getting the input string as:

    test<cr><lf>
    

    where <cr> and <lf> are ASCII codes 0x13 and 0x10 respectively.

    When you chomp it, it removes the <lf> but leaves the <cr> there.

    It’s almost certainly an interaction issue between Eclipse, Cygwin and Windows, disagreeing on what the end-of-line character sequence should be. I couldn’t replicate your problem with just Perl/Cygwin or Perl/Windows but this command gives similar results (in Cygwin):

    echo 'test^M' | perl qq.pl | sed 's/^M/\n/g'
    

    (qq.pl is your script and "^M" is the actual CTRL-M). Here’s the output in text form:

    4 6
    |test| |test
    |
    4 5
    

    and octal dump:

    0000000 2034 0a36 747c 7365 7c74 7c20 6574 7473
              4       6  \n   |   t   e   s   t   |       |   t   e   s   t
            064 040 066 012 174 164 145 163 164 174 040 174 164 145 163 164
    0000020 7c0a 340a 3520 000a
             \n   |  \n   4       5  \n  \0
            012 174 012 064 040 065 012 000
    0000027
    

    So I’d say that your input is putting on both <cr> and <lf>, and the print is translating <cr> to <lf> (or just doing the same thing for both of them).

    If you need a workaround for your environment, you can replace your chomp line with:

    $input =~ s/\r?\n$//;
    

    as in:

    use warnings;
    use strict;
    my $test = "test";
    my $input = <STDIN>;
    print length $test ," ",length $input,"\n";
    $input =~ s/\r?\n$//;
    print "|$test| |$input|\n";
    print length $test," ",length $input,"\n";
    if ($test eq $input) {
        print "TIME TO QUIT";
    }
    

    which works on Cygwin for the test data I used (check it for your own situation, of course), but you may find you can solve it better by using tools that all agree on the line end sequence (eg, Perl for Windows rather than the Cygwin one may do the trick for you).

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.