Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

oooohhhhhh great ones, I have a method in a class

sub SendMessage{ my $self=shift; print "Please enter message:\n"; my $message=<STDIN>; print "Please enter destination of message:\n"; my $to=<STDIN>; }
The problem is, it doesn't allow input for the $message. It immediately prints the destination line and then waits for that input. Do I need to clear STDIN or something?Please help me!!!

thanks, anon

Replies are listed 'Best First'.
Re: clear STDIN
by Belgarion (Chaplain) on Apr 21, 2004 at 18:23 UTC

    You must not have posted the complete code. When I run your routine, I get the first print, and then it waits until I enter a line, and then I get the second print, and it waits until I enter a line.

Re: clear STDIN
by Fletch (Bishop) on Apr 21, 2004 at 18:51 UTC
Re: clear STDIN
by Zaxo (Archbishop) on Apr 21, 2004 at 18:36 UTC

    It works for me. Linux 2.4.23, perl 5.8.3. Are you running this in a pipe or with redirected STDIN?

    After Compline,
    Zaxo

Re: clear STDIN
by TilRMan (Friar) on Apr 22, 2004 at 04:37 UTC

    Presumably you shouldn't have to flush (clear) STDIN unless something else in your program is going wrong. You might be able to figure out where the extra input is coming from by printing out $message immediately after you read it. If that doesn't help, a hexdump might.

    my $message = <STDIN>; print qq{\$message = "$message"\n}; printf "%02x ", ord for split //, $message; # hexdump