Hi Todd, Todd W wrote on 16.12.2004:
> >"Robert" <[EMAIL PROTECTED]> wrote in message >news:[EMAIL PROTECTED] >> I have seen in a few scripts now, including some of the articles that Mr. >> Schwartz has written. I have read it does something with the buffers but >on >> a more technical level what is that? >> >> Robert >> > >Along with the other explinations, consider an example: > >[EMAIL PROTECTED] trwww]$ perl >use warnings; >use strict; > >foreach my $i ( 1 .. 5 ) { > print($i, '...'); > sleep( 1 ); >} >print( "\n" ); > >$| = 1; >sleep( 1 ); > >foreach my $i ( 1 .. 5 ) { > print($i, '...'); > sleep( 1 ); >} >print( "\n" ); >^D >1...2...3...4...5... >1...2...3...4...5... > >The first line is all printed out at once. The second line prints >'1...' then waits a second then prints '2...' and so on. > That's what I knew about $|, too. But with the following script, it does not work as expected: ___BEGIN CODE___ #!/usr/bin/perl -wT use CGI; use strict; use LWP::UserAgent; my $q = new CGI; print $q->header(-type=>'text/html', -charset=>'utf-8'), $q->start_html("URL-Checker"), $q->h1('URL-Checker'); if ($q->param) { my $input = $q->param('input'); my @urls = split /[\r\n]+/, $input; my $fh = $q->upload('input_file'); while (<$fh>) { my @line = split /[\r\n]+/; push @urls, @line; } for (@urls) { # Hinzufügen des Schemas $_ = "http://" . $_ unless /^http/; my $browser = LWP::UserAgent->new( ); # Um eine automatische Weiterleitung zu vermeiden: weitergeleitete URLs erscheinen als invalid! $browser->requests_redirectable([]) if ($q->param('no_redirect')); my $response = $browser->get($_); if ($response->status_line eq "200 OK") { print qq{<p><span style="color:green">'$_'</span> is valid</p>}; } else { print qq{<p><span style="color:red">'$_'</span> is not valid<br /><b>Response status:</b> }, $response->status_line, "</p>"; } } } else { # html form is displayed here } print $q->end_html; ___END CODE___ This checks all URLs passed to the script and prints them out at once. When I add $| = 1; somewhere near the top, it also seems to buffer the output. I would expect the lines to appear one after the other. What am I doing wrong? Thanks, Jan -- There are two major products that come out of Berkeley: LSD and UNIX. We don't believe this to be a coincidence. - Jeremy S. Anderson -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>