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 | |
by Corion (Patriarch) on Oct 19, 2007 at 20:36 UTC | |
by goibhniu (Hermit) on Oct 19, 2007 at 21:01 UTC |