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 8637719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:32:40+00:00 2026-06-12T10:32:40+00:00

I thought this would be simple enough. I have two arrays, and I want

  • 0

I thought this would be simple enough. I have two arrays, and I want to print a sentence with numbers from these arrays into a file. I tried this:

chomp $array1[$x];
chomp $array2[$x];
print FILE "Number1: $array1[$x] \& Number2: $array2[$x] Some Words\n";

Which gives me:

Number1: 0
 & Number2: 87.3
 Some Words

(Numbers here are just examples.)

Any idea why this is happening?
I’ve tried using

$array1[$x] =~ s/\n//g;
$array2[$x] =~ s/\n//g;

as well, but it hasn’t fixed anything.
Also, if I explicitly place these extra newlines in, like so:

print FILE "Number1: $array1[$x]\n \& Number2: $array2[$x]\n Some Words\n"

I get the same output, so the unwanted newlines aren’t being added anymore. Why?

  • 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-06-12T10:32:41+00:00Added an answer on June 12, 2026 at 10:32 am

    As the file was created on Windows it likely has CRLF (i.e. \r\n) line termination, not just LF. chomp will by default only remove the LF.

    This line will remove LF with an optional preceding CR:

    $array1[$x] =~ s/\r?\n//;
    

    Alternatively, change $/ (the default “input record separator”) to contain \r\n, at which point chomp should correctly strip both.

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

Sidebar

Related Questions

I would have thought this one would be simple but I'm trying to change
I thought that this would be simple enough, but I just can't get my
I thought this would be simple enough but somethings wrong. The only Bootstrap gem
I thought this would be fairly simple but it turns out not to work
OK so I thought this would be pretty simple but it's tripping me up..
I thought it would be as simple as this... $('#yourSelect').change(function () { if ($(this).val()
This is what I thought would be a simple select clause, however the following
This should be so simple... I thought it would be nice to try the
I thought this would be fairly easy, but I'm totally baffled. I want one
I thought this would be pretty easy but I'm running into all sorts of

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.