Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

What exactly does "$| = 1;" do?
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



Report this thread to moderator Post Follow-up to this message
Old Post
Robert
11-30-04 08:55 PM


Re: What exactly does "$| = 1;" do?
> 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
>

Since this is a general Perl question not related to CGI it is better
asked to beginners@perl.org....

perldoc perlvar

Will give probably the least friendly and most technical version.
Specifically under OUTPUT_AUTOFLUSH.  The tricky parts being that it is
specifically the "currently selected" output, see,

perldoc -f select (first form)

For more on that, and that buffering may or may not be implemented for a
given type of handle (though most are).

Helps?

http://danconia.org

Report this thread to moderator Post Follow-up to this message
Old Post
Wiggins d Anconia
11-30-04 08:55 PM


Re: What exactly does "$| = 1;" do?
Robert [R], on Tuesday, November 30, 2004 at 09:15 (-0500) contributed
this to our collective wisdom:

R> I have seen in a few scripts now, including some of the articles that Mr.
R> Schwartz has written. I have read it does something with the buffers but 
on
R> a more technical level what is that?

it flushes output by default, so every write is really written.
= do not buffer.

--

..m8s, cu l8r, Brano.

[Assembler Command: RCP: Reschedule Car Payments]



Report this thread to moderator Post Follow-up to this message
Old Post
Ing. Branislav Gerzo
11-30-04 08:55 PM


Re: What exactly does "$| = 1;" do?
>>>>> "Wiggins" == Wiggins d Anconia <wiggins@danconia.org> writes:

Wiggins> Since this is a general Perl question not related to CGI it is bett
er
Wiggins> asked to beginners@perl.org....

Actually, I have sympathy for this one.  It's most often used in CGI
scripts so that a naive "system" invocation doesn't come out before
the headers.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training
!

Report this thread to moderator Post Follow-up to this message
Old Post
Randal L. Schwartz
11-30-04 08:55 PM


Re: What exactly does "$| = 1;" do?
"Robert" <catcher@linuxmail.org> wrote in message
news:20041130141505.9079.qmail@lists.develooper.com...
> 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:

[trwww@waveright 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.

Todd W.





Report this thread to moderator Post Follow-up to this message
Old Post
Todd W
12-16-04 08:55 PM


Re: What exactly does "$| = 1;" do?
Hi Todd,

Todd W wrote on 16.12.2004:

>
>"Robert" <catcher@linuxmail.org> wrote in message
>news:20041130141505.9079.qmail@lists.develooper.com... 
=2E 
>on 
>
>Along with the other explinations, consider an example:
>
>[trwww@waveright trwww]$ perl
>use warnings;
>use strict;
>
>foreach my $i ( 1 .. 5 ) {
>  print($i, '...');
>  sleep( 1 );
>}
>print( "\n" );
>
>$| =3D 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 no=
t work as expected:

___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) {
# Hinzuf=FCgen des Schemas
$_ =3D "http://" . $_ unless /^http/;
my $browser =3D LWP::UserAgent->new( );
# Um eine automatische Weiterleitung zu vermeiden: weitergeleitete =
URLs erscheinen als invalid!
$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<=
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 $| =3D 1; somewhere near the top, it also seems to buffer the output=
=2E I would expect the lines to appear one after the other.

What am I doing wrong?

Thanks,

Jan
--=20
There are two major products that come out of Berkeley: LSD and UNIX. We do=
n't believe this to be a coincidence. - Jeremy S. Anderson

Report this thread to moderator Post Follow-up to this message
Old Post
Jan Eden
12-20-04 01:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL CGI Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:25 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.