[tpm] chomp problem

Emil Janev ejanev at gmail.com
Mon Feb 7 10:04:37 PST 2011


Hi Omid,

Most probably you do not need to reinstall Perl :)

Just disable the buffering on the STDOUT handle:

use warnings;
use strict;

use FileHandle;

STDOUT->autoflush;

while (<DATA>) {
        chomp $_;
        print "$_";
        sleep 1;

}

__END__
a
b
c
d
e
f
g
h


On Mon, Feb 7, 2011 at 9:21 AM, Omid Gulban <omid.gulban at sickkids.ca> wrote:

> Hello All,
>
> I have used chomp a countless number of times before and had no problem. I
> am also well aware of the end of line characters on various platforms. What
> confuses me the most as well is
> when I included a "sleep 1; " in the code as listed below:
>
> use warnings;
> use strict;
>
> while (<DATA>) {
>        chomp $_;
>        print "$_";
>         sleep 1;
>
> }
>
> __END__
> a
> b
> c
> d
> e
> f
> g
> h
>
>
> I expected a 1 second delay in between the print statements. BUT PERL waits
> 8 (1 second for a,b,c,d...h)  seconds and prints everything together!
> maybe I should uninstall perl and reinstall it again!
>
> I have used chomp for about 8 years and never seen this.
>
>
>
>
> Thanks
> O
> ________________________________________
> From: toronto-pm-bounces+gulban=sickkids.ca at pm.org[toronto-pm-bounces+gulban=
> sickkids.ca at pm.org] On Behalf Of Omid Gulban [omgulban at yahoo.ca]
> Sent: February 4, 2011 3:42 PM
> To: tpm at to.pm.org
> Subject: [tpm] chomp problem
>
> Hello All,
>
> I have a simple script shown below:
> on windows xp platform.
>
>
>
> use warnings;
> use strict;
>
> while (<DATA>) {
>        chomp $_;
>        print "$_";
> }
>
> __END__
> a
> b
> c
> d
> e
> f
> g
> h
>
>
> Why do I get an output that looks like this:
> a
> ab
> bc
> cd
> de
> ef
> fg
> ghh
>
> I expected to see:
> abcdefg
>
>
> Thanks
> O
>
>
> This e-mail may contain confidential, personal and/or health
> information(information which may be subject to legal restrictions on use,
> retention and/or disclosure) for the sole use of the intended recipient. Any
> review or distribution by anyone other than the person for whom it was
> originally intended is strictly prohibited. If you have received this e-mail
> in error, please contact the sender and delete all copies.
> _______________________________________________
> toronto-pm mailing list
> toronto-pm at pm.org
> http://mail.pm.org/mailman/listinfo/toronto-pm
>



-- 
Emil Janev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20110207/0c84be8e/attachment.html>


More information about the toronto-pm mailing list