in reply to problem with input command

I have written a sample program for you, using a hash. Maybe you won't truly understand it right now, but you will as you get more experienced with Perl. I'd suggest you read some books, tutorials and the Perl manual.

Click here to see my sample program for you :
#!perl #these will help you write correct Perl scripts: use strict; use warnings; # here, we declare all command names, and what subprocedure they shoul +d call my %commands = ( hello => \&hello, world => \&world, hacker => \&japh, ); # now this is the user interface, or the command line while (1) { print "\n>> "; my $command = <STDIN>; #remove the newline from the end of the command chomp $command; #let's check if %commands has the given gommand if (exists $commands{lc($command)}) { &{$commands{$command}}; } else { print "I don't get you...\n"; } } # and the actual subprocedures; sub hello { #the obligate first output :) print "Hello World!\n"; } sub world { print "World, Hello!\n"; } sub japh { print "I am just another Perl hacker\n"; }


Try entering the commands 'hello', 'world' and 'hacker'.
Note that this program won't support arguments. That would be too complicated to show in a simple sample program like this.

Anyway, welcome to Perl Monks, and good luck learning Perl! As you will discover, it's an amazing language.

Update: there was an error in the code. I fixed it. I also corrected a spelling error.




"2b"||!"2b";$$_="the question"
Besides that, my code is untested unless stated otherwise.
One more: please review the article about regular expressions (do's and don'ts) I'm working on.