For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > July 2005 > Re: Numeric or character ?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Numeric or character ?
Sven-Thorsten Fahrbach

2005-07-26, 5:02 pm

> In general, one checks if input conforms to a certain format by
> using an appropriate regex match. In this case, it is a very
> simple one:
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> my $input;
>
> $| = 1;


I'm just being interested: is there any specific reason why you make output unbuffered here? I think it's not necessary for this script but maybe something has escaped me...

>
> do {
> print "Please enter and integer between 0 and 255: ";
> $input = <STDIN>;
> } until $input =~ /^(\d\d?\d?)$/ and 0 + $1 < 256;
>
> print "You entered: $input\n";

Anno Siegel

2005-07-27, 9:03 am

Sven-Thorsten Fahrbach <sven-thorsten.fahrbach@gmx.net> wrote in comp.lang.perl.misc:
>
> I'm just being interested: is there any specific reason why you make
> output unbuffered here? I think it's not necessary for this script but
> maybe something has escaped me...


Autoflushing (which is more to the point than "unbuffered") isn't
exactly needed here, but it's convenient to have. Its main purpose
is to match the flushing behavior of STDOUT and STDERR so that messages
on both appear on the screen when they are printed, not when a buffer
happens to overflow. Otherwise, error messages and normal output may
appear out of sequence, which can be confusing.

I put "$| = 1" in all my scripts (not modules), and only take it out
when the script happens to do mass IO via STDOUT (as in a filter).

Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com