Why am I getting extra line breaks on a webpage that I load using Perl?

I am writing a simple Perl script (on Windows) to download a get request response to a file URL. Pretty straightforward. Unless it is written to the output file, I get extra line breaks. So instead of:

<head>
  <title>title</title>
  <link .../>
</head>

I get

<head>

  <title>title</title>

  <link .../>

</head>

Here's the Perl script:

use LWP::Simple;

my $url = $ARGV[0];
my $content = get($url);

open(outputFile, '+>', $ARGV[1]);

print outputFile $content;

close(outputFile);

I guess I can just get wget for Windows , but now it bothers me. How do I get rid of extra gaps ??

+3
source share
3 answers
  • >+. .
  • LWP::Simple getstore. LWP::Simple, ?
  • open / :crlf win32, \n \r\n. , , \r\n, . , , binmode :raw . LWP .
+12

, $content CRLF, IO Perl LF → CRLF. (Internally, "\n" - Perl, LF).

binmode(outputFile);

open, $content.

+4

chomp ($ content) . , \n.

EDIT: , , chomp , , , chomp chomp , , , \n\n ? , . : , - , 2+\n, 2+\r, . \n , , ()

$content = ~ s/[\n\r] +/\n/g;

EDITED , ! -.... ,

-4

Source: https://habr.com/ru/post/1769553/


All Articles