[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Why is CNTL-D still in buffer??



The following snipet of code does not do what
I thought it would do on MacPerl, BUT it runs
fine under Perl 5.001 on Linux 1.2.13.

Is there a way to fix this?  I welcome suggestions.
Thank you.

The intent is to read a set of user input lines,
join them into a single string, check the string length
and if too long, ask them to re-enter it...

On a Quadra 650 with Mac Perl Version 5.1.0r2
on the second time through the do{}while loop
it acts like the ^D(cntl-D) used to end
the first entry of multiple lines is still
in STDIN, as the loop jumps right through
the subroutine getMLInput with 
length($in_data{'comments'} = 0.

This does however work under Unix.
----

====>> SAMPLE I/O
Please limit your comments to 80 characters maximum
Enter ^D when done.
Enter your comments> Quack, quack, quack,Quack, quack, quack
next line> Quack, quack, quack.  Quack, quack, quack
next line> Quack, quack, quack. Quack, quack, quack
next line> Quack, quack, quack. Quack, quack, quack.
next line> Quack, quack, quack. Quack, quack, quack.
next line> Please limit your comments to 80 characters maximum
Enter ^D when done.
Enter your comments> 
Thank you for your comments!
 Donald Duck 
 dduck@toon.com 
la,ca,usa 
Sat Dec  7 09:34:45 1996
====>> SAMPLE I/O

see, it jump right over, just like the ^D was stuck in STDIN

====>> CODE
#maximum number of comment characters (for testing)
$max_comments_size = 80;    

#
#    get user comments
#    check of comments are too long
#
do
{
        print "Please limit your comments to $max_comments_size characters
maximum\n";
        $in_data{'comments'} = getMLInput("Enter your comments");
        
} while ( length($in_data{'comments'}) > $max_comments_size);


#
#       get multiple line user input
#       and convert to a single string
#
sub getMLInput {
        my($prompt) = @_;          # prompt to get user input
        
        my ($UserInput) = "";    
        my ($line) = "";    
        my (@MLinput) = ();
        
#get input from user
        print ("Enter ^D when done.\n");
        print ("$prompt> ");
        while ($line = <STDIN>) {
        push @MLinput, $line;
                print ("next line> ");
        }
        $UserInput = join("",@MLinput);
        return $UserInput;
}




-- 
************************************************************
Dr. Samuel D. Gasster
gasster@pacificnet.net
************************************************************