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

Hi Monks!

I'm having problems when using <STDIN> in scalar context. Example: when runing the script below the whole script is executed without stoping to recive input. $some_string is automatically set to "". The problem dosen't occure if the <STDIN> is called in scalar context in a while loop, or if <STDIN> is called in list context. What's wrong? I'm greatfull for all suggestions!

%map = qw(red apple green leaves blue ocean); print "A string please: "; chomp($some_string = <STDIN>); print "The value for $some_string is $map{$some_string}\n";
Thanks!

update (broquaint): fixed ending <code> tag

Replies are listed 'Best First'.
Re: Problems with <STDIN> in scalar context
by VSarkiss (Monsignor) on Feb 17, 2003 at 18:18 UTC
Re: Problems with <STDIN> in scalar context
by jasonk (Parson) on Feb 17, 2003 at 18:06 UTC

    You need to indicate how you are running your script, and some information about your environment, because the script works fine as it is, so you have a problem that is not related to the code you included here.