in reply to problem with input command
#!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"; }
|
|---|