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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:22:47+00:00 2026-05-23T12:22:47+00:00

I’m pretty new to Perl. My Perl program is getting the HTTP request message

  • 0

I’m pretty new to Perl. My Perl program is getting the HTTP request message from browser, I want to detect the last blank line.

I was trying to use $_ =~ /\S/, but which doesn’t work:

while (<CONNECTION>) {
  print $_;
  if ($_ =~ /\S/) {print "blank line detected\n"; }
}

the output is

GET / HTTP/1.1
blank line detected
Host: xxx.ca:15000
blank line detected
User-Agent: Mozilla/5.0 (X11; Linux i686; rv:5.0) Gecko/20100101 Firefox/5.0
blank line detected
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
blank line detected
Accept-Language: en-us,en;q=0.7,zh-cn;q=0.3
blank line detected
Accept-Encoding: gzip, deflate
blank line detected
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
blank line detected
Connection: keep-alive
blank line detected
Cookie: __utma=32770362.1159201788.1291912625.1308033463.1309142872.11; __utmz=32770362.1307124126.7.3.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=Manitoba%20Locum%20Tenens%20Program; __utma=70597634.1054437369.1308785920.1308785920.1308785920.1; __utmz=70597634.1308785920.1.1.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=leung%20carson
blank line detected



I was trying to use chomp(), which does not work for me too:

  while (<CONNECTION>) {
    chomp(); 
    print "$_\n";
    if ($_ eq "") {print "blank line detected\n"; }
  }

the output:

GET / HTTP/1.1
Host: xxx.ca:15000
User-Agent: Mozilla/5.0 (X11; Linux i686; rv:5.0) Gecko/20100101 Firefox/5.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.7,zh-cn;q=0.3
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection: keep-alive
Cookie: __utma=32770362.1159201788.1291912625.1308033463.1309142872.11; __utmz=32770362.1307124126.7.3.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=Manitoba%20Locum%20Tenens%20Program; __utma=70597634.1054437369.1308785920.1308785920.1308785920.1; __utmz=70597634.1308785920.1.1.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=leung%20carson

Thanks in advance~

  • 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-23T12:22:47+00:00Added an answer on May 23, 2026 at 12:22 pm

    To detect lines with nothing but whitespace,

    while (<CONNECTION>) {
      print $_;
      if ($_ =~ /\S/) {print "blank line detected\n"; }
    }
    

    should be

    while (<CONNECTION>) {
       print $_;
       if ($_ !~ /\S/) {print "blank line detected\n"; }
    }
    

    Or for short,

    while (<CONNECTION>) {
       print;
       if (!/\S/) {print "blank line detected\n"; }
    }
    

    The reason

    while (<CONNECTION>) {
       chomp(); 
       print "$_\n";
       if ($_ eq "") {print "blank line detected\n"; }
     }
    

    might not work is because HTTP header lines end with \r\n. You’d need

    while (<CONNECTION>) {
       s/\r?\n//; 
       print "$_\n";
       if ($_ eq "") {print "blank line detected\n"; }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.