The problem is multi word commands. When I type "log" into my system, I have the program responds with "Log files inactive, type 'log start' to begin logging. I was planning to have another hash named "log" to then hold the routines for it.%command_list = qw( quit end_program() greeting greeting() time systime() help help() log log_status() );
I am using strict and believe this is the problem, but I believe there should be a way to do this while using "strict". Here is the error: Can't use string ("log") as a HASH ref while "strict refs" in use at....... I know the error isn't due to using the word "log".%log = qw(start start_logs() stop stop_logs() ); }
Any suggestions on how to fix this || other methods that would work better are greatly appreaciated. Thanks, Thoth$command = <STDIN>; # assume $command="log start" @cl =split / /,$command; # if we have multi word command... if (!(defined($cl[1]))){ #single word command chop $cl[0]; $command_action= $command_list{$cl[0]}; } else { #multi word command chop $cl[1]; print "$cl[0]\n"; #command print "$cl[1]\n"; #options to that command $command_action= $cl[0]{$cl[1]}; #trying to set $command_action += to "$log{start}; } eval $command_action; die "\n" if $@; }
In reply to Trying to simulate a CLI using hashes... by thoth
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |