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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:32:49+00:00 2026-05-19T04:32:49+00:00

Good day, For work I am suddenly required to know Perl, and though I

  • 0

Good day,

For work I am suddenly required to know Perl, and though I have dabbled in those arts years ago, I seem to be completely lost. For a Haskell/Java programmer, all these unstructured typing can get on the nerves.

However, I wrote this sub that is supposed to take an array of single-line strings and concatenate them to a single, multi-lined strings. I had it Like so:

sub unlines {
    my ( @lines ) = @_;
    my $str = "";
    foreach $line ( @lines ) {
        $str = join $str, chomp($line), "\n";
    }
    return $str;
}

And then I wanted to test it, of course:

print unlines(("GET / http1.1", "Host: localhost", ""));

And the result of the thing is

000

And a lot of newlines. I have absolutely no idea why that is. Anyone can help me and explain, perhaps, how all these argument passing to subs in Perl works? It seems to be very interesting to work with things like @_ and shift, but the typing… it’s a nightmare.

Thanks for listening.

  • 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-19T04:32:50+00:00Added an answer on May 19, 2026 at 4:32 am

    Your trouble lies in how chomp works; it doesn’t return the chomped variable, it returns the number of characters removed and alters the variable in-place.

    So chomp first and join later, like this…

    C:\temp>cat test.pl
    my @lines = ('abc','def');
    chomp @lines;
    print join "\n",@lines;
    
    C:\temp>test.pl
    abc
    def
    C:\temp>
    

    And for completeness, here’s how your unlines() could look

    sub unlines {
        my @lines = @_;
        chomp @lines;    
        return join "\n", @lines;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good day, I have this problem with Html.DropDownListFor which I can't seem to work
Good day everyone. I have been having the same problem all day at work
Good day I have manage to create my small and simple application, work with
Good day. I have little usage of Flash CS4, however i have to build
Good day, If I have for example the documents which have the following fields
Good day, I have run into some problem in the Zend_Cache_Frontend_Page. I want to
Good Day, I have two connection strings defined in my web.config file. <connectionStrings> <add
Good Day, I have been trying various methods both found on here and in
Good day, I have been searching for a way to format output using writeline/write
Hello and good day to all. I have a little question about like statement

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.