Ask a Question related to PERL Beginners, Design and Development.
-
Nilay Puri #1
FW: special vars
> -----Original Message-----
> From: Nilay Puri, Noida
> Sent: Wednesday, February 04, 2004 11:37 AM
> To: Perl (E-mail)
> Subject: FW: special vars
>
>
>
> -----Original Message-----
> From: Nilay Puri, Noida
> Sent: Wednesday, February 04, 2004 11:32 AM
> To: Perl (E-mail)
> Subject: special vars
>
> Hi all,
>
> Can any one help me understand the usage of special variable $| ?
>
> I know the description of this var. If set to nonzero, forces a flush
> after every write or print.
>
> But I am not able to understand its importance.
>
> If I am reading a file and writing the contents in a separat file after
> some processing.
> What will happen if I set $|=1 ?
>
> Thanks,
> NP
>
>
>
>Nilay Puri Guest
-
#26050 [Opn->Bgs]: Unable to use CONST vars in other CONST vars
ID: 26050 Updated by: sniper@php.net Reported By: kris dot hofmans at pandora dot be -Status: Open +Status: ... -
#26050 [NEW]: Unable to use CONST vars in other CONST vars
From: kris dot hofmans at pandora dot be Operating system: Linux 2.4.21 PHP version: 5CVS-2003-10-31 (dev) PHP Bug Type: ... -
our vs. use vars
Howdy group, In developing a module and I am torn. I want to use the newer our $variable; but to make it work with pre 5.6 Perl (or whatever... -
env vars using perl
Hi all I am a newbie in perl. I can use this to get all the env variables #!/bin/perl foreach $key ( sort keys %ENV ) { print "$key... -
Alternative to use vars
I am using use vars qw ($scalar @array %hash); in my program. I would like to know how to declare this in an alternative way using our and EXPORT.... -
Jeff 'Japhy' Pinyan #2
Re: FW: special vars
On Feb 4, Nilay Puri, Noida said:
Most filehandles buffer their output until a newline is reached. For>> Can any one help me understand the usage of special variable $| ?
>>
>> I know the description of this var. If set to nonzero, forces a flush
>> after every write or print.
example, try this code:
for (1 .. 5) {
print STDOUT;
sleep 1;
}
At the end of 5 seconds, you'll get "12345". Compare that with this:
for (1 .. 5) {
print STDERR;
sleep 1;
}
Here, you get 1, then a pause, 2, then a pause, and so on. STDOUT is
buffered, whereas STDERR is not. Now, if you want to UNbuffer STDOUT, you
set $| to 1.
$| = 1;
for (1 .. 5) {
print STDOUT;
sleep 1;
}
Now you get 1, pause, 2, pause, 3, pause, 4, pause, 5, pause.
$| has its own value for each filehandle. In order to make filehandle FOO
unbuffered, you need to select() FOO and then set $| to 1.
my $old_fh = select FOO;
$| = 1; # now FOO is unbuffered
select $old_fh; # go back to whatever filehandle was previous selected
--
Jeff "japhy" Pinyan [email]japhy@pobox.com[/email] [url]http://www.pobox.com/~japhy/[/url]
RPI Acacia brother #734 [url]http://www.perlmonks.org/[/url] [url]http://www.cpan.org/[/url]
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
[ I'm looking for programming work. If you like my work, let me know. ]
Jeff 'Japhy' Pinyan Guest
-
Eternius #3
Re: FW: special vars
Nilay Puri wrote:
if u use an OS like linux (which will not write things imediately to>>> -----Original Message-----
>>From: Nilay Puri, Noida
>>Sent: Wednesday, February 04, 2004 11:37 AM
>>To: Perl (E-mail)
>>Subject: FW: special vars
>>
>>
>>
>> -----Original Message-----
>>From: Nilay Puri, Noida
>>Sent: Wednesday, February 04, 2004 11:32 AM
>>To: Perl (E-mail)
>>Subject: special vars
>>
>>Hi all,
>>
>>Can any one help me understand the usage of special variable $| ?
>>
>>I know the description of this var. If set to nonzero, forces a flush
>>after every write or print.
>>
>>But I am not able to understand its importance.
>>
>>If I am reading a file and writing the contents in a separat file after
>>some processing.
>>What will happen if I set $|=1 ?
>>
>>Thanks,
>>NP
>>
>>
>>
>>
disc) this forces it to do so.
Eternius Guest
-
Bastian Angerstein #4
AW: FW: special vars
It is important believe me.
Especialy if you are writting to logfiles, databases and unix named pipes.
If in this context buffered io is on it will happen that if you prints
something to
a file or anywhere not the whole line is dumped only the stuff what was in
the buffer
when the buffer was flushed because of its size the last time.
if you give out the line:
Hello, I am here./n
Buffered it could look like this at the destination:
Hello, I a
Unbuffered it will look like this:
Hello, I am here./n
Beware THERE IS A DIFFERENCE OF PRINTING TO A FILE, PIPE, PROGRAM and a TTY
/ COMMANDLINE.
See Fcntl, File::Handle, Io::Handle at cpan for more.
-----Ursprungliche Nachricht-----
Von: Eternius [mailto:eternius@opposoft.de]
Gesendet: Mittwoch, 4. Februar 2004 12:00
An: [email]beginners@perl.org[/email]
Betreff: Re: FW: special vars
Nilay Puri wrote:
if u use an OS like linux (which will not write things imediately to>>> -----Original Message-----
>>From: Nilay Puri, Noida
>>Sent: Wednesday, February 04, 2004 11:37 AM
>>To: Perl (E-mail)
>>Subject: FW: special vars
>>
>>
>>
>> -----Original Message-----
>>From: Nilay Puri, Noida
>>Sent: Wednesday, February 04, 2004 11:32 AM
>>To: Perl (E-mail)
>>Subject: special vars
>>
>>Hi all,
>>
>>Can any one help me understand the usage of special variable $| ?
>>
>>I know the description of this var. If set to nonzero, forces a flush
>>after every write or print.
>>
>>But I am not able to understand its importance.
>>
>>If I am reading a file and writing the contents in a separat file after
>>some processing.
>>What will happen if I set $|=1 ?
>>
>>Thanks,
>>NP
>>
>>
>>
>>
disc) this forces it to do so.
--
To unsubscribe, e-mail: [email]beginners-unsubscribe@perl.org[/email]
For additional commands, e-mail: [email]beginners-help@perl.org[/email]
<http://learn.perl.org/> <http://learn.perl.org/first-response>
Bastian Angerstein Guest
-
Wiggins D Anconia #5
Re: FW: special vars
> Nilay Puri wrote:
>That is misleading and not necessarily true. It tells Perl to unbuffer>
> if u use an OS like linux (which will not write things imediately to
> disc) this forces it to do so.
>
the I/O but not the OS. The OS decides what will and won't get written
to disc, based on kernel settings, harddrive settings, etc. Don't
confuse the two...
[url]http://danconia.org[/url]
Wiggins D Anconia Guest
-
Eternius #6
Re: FW: special vars
then I guess, I didn't understand it myself
Wiggins D Anconia wrote:
>>>>Nilay Puri wrote:
>>
>>>>if u use an OS like linux (which will not write things imediately to
>>disc) this forces it to do so.
>>
>
> That is misleading and not necessarily true. It tells Perl to unbuffer
> the I/O but not the OS. The OS decides what will and won't get written
> to disc, based on kernel settings, harddrive settings, etc. Don't
> confuse the two...
>
> [url]http://danconia.org[/url]
>Eternius Guest
-
Rob Dixon #7
Re: FW: special vars
Eternius wrote:
Disk drives have their own cache. CPUs now have their own first, second and>
> Wiggins D Anconia wrote:
>>> >> >>Nilay Puri wrote:
> >>
> >> >> >>if u use an OS like linux (which will not write things imediately to
> >>disc) this forces it to do so.
> >>
> >
> > That is misleading and not necessarily true. It tells Perl to unbuffer
> > the I/O but not the OS. The OS decides what will and won't get written
> > to disc, based on kernel settings, harddrive settings, etc. Don't
> > confuse the two...
> >
> > [url]http://danconia.org[/url]
> >
> Then I guess, I didn't understand it myself.
third level memory caching. The file system is likely to have two caches of
its own per file, and the language at least one more in RAM.
Disabling output buffering in Perl should be seen as a nicety that helps
debugging, but not much else. Only a hardware solution can guard against
losing power at the wrong time.
Rob
Rob Dixon Guest
-
Drieux #8
Re: special vars
On Feb 4, 2004, at 10:23 AM, Rob Dixon wrote:
[..]Minor Nit, yes I know that the thread has> Disabling output buffering in Perl should be seen as
> a nicety that helps debugging, but not much else. Only
> a hardware solution can guard against losing power at the wrong time.
been about disk and/or filesystem I/O - but
the need to disable output buffering becomes
very important when one is doing client-server
code over a socket and/or pipe.
Nothing like having one side waiting for the otherside
to do something - but the message did not get sent because
it is sitting in a buffer waiting to be flushed...
ciao
drieux
---
Drieux Guest



Reply With Quote

