For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > December 2004 > To buffer or not ($|)









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author To buffer or not ($|)
Jan Eden

2004-12-29, 8:55 am

Hi all,

I already sent this as a reply to another post, but did not receive an answ=
er. In the following script, the results are not printed at once, line by l=
ine, but in one block after several seconds:

___BEGIN CODE___

#!/usr/bin/perl -wT

use CGI;
use strict;
use LWP::UserAgent;

my $q =3D new CGI;

print $q->header(-type=3D>'text/html', -charset=3D>'utf-8'),
$q->start_html("URL-Checker"),
$q->h1('URL-Checker');
=20
if ($q->param) {
my $input =3D $q->param('input');
my @urls =3D split /[\r\n]+/, $input;
my $fh =3D $q->upload('input_file');
while (<$fh> ) {
my @line =3D split /[\r\n]+/;
push @urls, @line;
}
for (@urls) {
$_ =3D "http://" . $_ unless /^http/;
my $browser =3D LWP::UserAgent->new( );
$browser->requests_redirectable([]) if ($q->param('no_redirect'));
my $response =3D $browser->get($_);
if ($response->status_line eq "200 OK") {
print qq{<p><span style=3D"color:green">'$_'</span> is valid</p>=
};
}
else { =20
print qq{<p><span style=3D"color:red">'$_'</span> is not valid<b=
r=20
/><b>Response status:</b> }, $response->status_line, "</p>";
}
}
}
else {
# html form is displayed here
}

print $q->end_html;

___END CODE___


I would expect that $| =3D 1 alters this behaviour - but it doesn't. Why?

Thanks,

Jan
--=20
Imagine if every Thursday your shoes exploded if you tied them the usual wa=
y. This happens to us all the time with computers, and nobody thinks of com=
plaining. - Jeff Raskin
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com