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

If I enter the alphabet h in together with the perl filname.pl command in Terminal ( perl filename.pl h ), it doesn't work.
It only works if I do it separately.
perl filename.pl
h


How do I make it work if I enter both together on the same line ? Thanks :)
#!/usr/bin/perl –w chomp(my $user_value = <STDIN>); if ($user_value eq "h") { print " hi \n"; }

Replies are listed 'Best First'.
Re: <STDIN> detects only input after perl script is run.
by SuicideJunkie (Vicar) on May 03, 2013 at 15:36 UTC

    perl filename.pl his passing "h" as a command line parameter. You will find it in @ARGV

    perl filename.pl h
    is providing no command line parameters, and sending "h" to STDIN

      Ahh thanks for the @ARGV . That answers my question :)
Re: <STDIN> detects only input after perl script is run.
by blue_cowdawg (Monsignor) on May 03, 2013 at 15:41 UTC

    If you wanted to send an "h" to standard input you should invoke your script

    echo "h" | perl filename.pl
    also another thought:
    #!/usr/bin/perl -w use strict; #damn fine idea my $user_value=<STDIN>; chomp $user_vaule;


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
      Noted on  use strict :)
Re: <STDIN> detects only input after perl script is run.
by karlgoethebier (Abbot) on May 03, 2013 at 16:49 UTC

    Perhaps you should think about using Getopt::Long or something similar?

    Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»