Click here to get back home

append to file

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
append to file Petr Vileta 03-20-2008
---> Re: append to file nolo contendere03-20-2008
| `--> Re: append to file nolo contendere03-20-2008
Posted by Petr Vileta on March 20, 2008, 9:11 pm
Please log in for more thread options
I have two simple scripts

------- script1.pl--------
#!/usr/bin/perl
use strict;
open O,">> x.txt";
print O "111\n";
sleep 10;
print O "111\n";
close O;
------- script1.pl--------

------- script2.pl--------
#!/usr/bin/perl
use strict;
open O,">> x.txt";
print O "222\n";
sleep 10;
print O "222\n";
close O;
------- script2.pl--------

I run script1.pl in time T and script2.pl in time T + 2 seconds. I expect
result

111
222
111
222

but I get

111
111
222
222

Why? Can anybody explain me it? I run my scripts on WindowsXP and ActivePerl
5.6.1.
Will be result the same on Linux platform?
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail from
another non-spammer site please.)

Please reply to <petr AT practisoft DOT cz>


Posted by nolo contendere on March 20, 2008, 10:10 pm
Please log in for more thread options
> I have two simple scripts
>
> ------- script1.pl--------
> #!/usr/bin/perl
> use strict;
> open O,">> x.txt";
> print O "111\n";
> sleep 10;
> print O "111\n";
> close O;
> ------- script1.pl--------
>
> ------- script2.pl--------
> #!/usr/bin/perl
> use strict;
> open O,">> x.txt";
> print O "222\n";
> sleep 10;
> print O "222\n";
> close O;
> ------- script2.pl--------
>
> I run script1.pl in time T and script2.pl in time T + 2 seconds. I expect
> result
>
> 111
> 222
> 111
> 222
>
> but I get
>
> 111
> 111
> 222
> 222
>
> Why? Can anybody explain me it? I run my scripts on WindowsXP and ActivePe=
rl
> 5.6.1.
> Will be result the same on Linux platform?
> --
> Petr Vileta, Czech republic
> (My server rejects all messages from Yahoo and Hotmail. Send me your mail =
from
> another non-spammer site please.)
>
> Please reply to <petr AT practisoft DOT cz>

try turning on autoflush. after use strict;, enter the line '|++;' in
each program.

Posted by nolo contendere on March 20, 2008, 10:10 pm
Please log in for more thread options
>
>
>
> > I have two simple scripts
>
> > ------- script1.pl--------
> > #!/usr/bin/perl
> > use strict;
> > open O,">> x.txt";
> > print O "111\n";
> > sleep 10;
> > print O "111\n";
> > close O;
> > ------- script1.pl--------
>
> > ------- script2.pl--------
> > #!/usr/bin/perl
> > use strict;
> > open O,">> x.txt";
> > print O "222\n";
> > sleep 10;
> > print O "222\n";
> > close O;
> > ------- script2.pl--------
>
> > I run script1.pl in time T and script2.pl in time T + 2 seconds. I expec=
t
> > result
>
> > 111
> > 222
> > 111
> > 222
>
> > but I get
>
> > 111
> > 111
> > 222
> > 222
>
> > Why? Can anybody explain me it? I run my scripts on WindowsXP and Active=
Perl
> > 5.6.1.
> > Will be result the same on Linux platform?
> > --
> > Petr Vileta, Czech republic
> > (My server rejects all messages from Yahoo and Hotmail. Send me your mai=
l from
> > another non-spammer site please.)
>
> > Please reply to <petr AT practisoft DOT cz>
>
> try turning on autoflush. after use strict;, enter the line '|++;' in
> each program.

sorry, i meant '$|++;'

Posted by John W. Krahn on March 21, 2008, 1:04 am
Please log in for more thread options
Petr Vileta wrote:
> I have two simple scripts
>
> ------- script1.pl--------
> #!/usr/bin/perl
> use strict;
> open O,">> x.txt";
> print O "111\n";
> sleep 10;
> print O "111\n";
> close O;
> ------- script1.pl--------
>
> ------- script2.pl--------
> #!/usr/bin/perl
> use strict;
> open O,">> x.txt";
> print O "222\n";
> sleep 10;
> print O "222\n";
> close O;
> ------- script2.pl--------
>
> I run script1.pl in time T and script2.pl in time T + 2 seconds. I
> expect result
>
> 111
> 222
> 111
> 222
>
> but I get
>
> 111
> 111
> 222
> 222
>
> Why? Can anybody explain me it?

http://perl.plover.com/FAQs/Buffering.html


> I run my scripts on WindowsXP and
> ActivePerl 5.6.1.
> Will be result the same on Linux platform?

Probably.



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall

Similar ThreadsPosted
FAQ 5.2 How do I change, delete, or insert a line in a file, or append to the beginning of a file? December 28, 2006, 3:03 pm
FAQ 5.2 How do I change, delete, or insert a line in a file, or append to the beginning of a file? February 24, 2007, 9:03 am
FAQ 5.2 How do I change, delete, or insert a line in a file, or append to the beginning of a file? May 12, 2007, 3:03 am
FAQ 5.2 How do I change, delete, or insert a line in a file, or append to the beginning of a file? October 11, 2007, 3:03 pm
FAQ 5.2 How do I change, delete, or insert a line in a file, or append to the beginning of a file? December 27, 2007, 9:03 am
FAQ 5.2 How do I change, delete, or insert a line in a file, or append to the beginning of a file? March 8, 2008, 3:03 am
FAQ 5.2 How do I change, delete, or insert a line in a file, or append to the beginning of a file? June 1, 2008, 9:03 pm
How to append a file accordingly? November 25, 2007, 9:30 pm
FAQ 5.2: How do I change one line in a file/delete a line in a file/insert a line in the middle of a file/append to the beginning of a file? December 7, 2004, 6:03 am
FAQ 5.2 How do I change one line in a file/delete a line in a file/insert a line in the middle of a file/append to the beginning of a file? January 27, 2005, 12:03 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap