in reply to Re^2: Conditional question
in thread Conditional question

#!usr/bin/perl -w #1 use strict; #2 print "type hw to print hello world script!\n"; #3, newline(s) missing my $cmd = <STDIN>; #4 STDIN if ( $cmd eq "hw" ) #5,6,7 $cmd, "=" should be "==" or "eq", "hw" must + be quoted { print "Hello, world\n"; #3, newline(s) missing } else { print "sorry I didn't understand the command.\n"; #8,3 "Print" -> "pri +nt", newline(s) missing }

I didn't count the missing my as an error, that could have been intended as a global variable instead of a lexical with global scope. I missed the chomp, and I had the \n after the print statements so the buffers get flushed. I'm not sure if Perl autoflushes buffers when alternating between printing to STDOUT and reading from STDIN.

Replies are listed 'Best First'.
Re^4: Conditional question
by goibhniu (Hermit) on Oct 19, 2007 at 20:16 UTC

    I now use warnings; instead of perl -w since Windows seems to ignore the she-bang line.


    I humbly seek wisdom.

      But Perl does not:

      C:\Projekte>type tmp.pl #!/usr/bin/perl -w use strict; my $foo; print $foo __END__ C:\Projekte>perl tmp.pl Use of uninitialized value in print at tmp.pl line 5.

        Your example behaves the same on my system as well. Based on my experience in multi-threaded win32::console, though, it seems there is some difference between -w and use warnings;. Is use warnings; the same as perl -W (capital W)? or something?


        I humbly seek wisdom.