After realizing that menus wern't going to cut it, I deicded to simulate a CLI into my program. I have a hash set up as %command_list, with the list of all of my commands, using eval to run the subroutines. example:
%command_list = qw( quit end_program() greeting greeting() time systime() help help() log log_status() );
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.
%log = qw(start start_logs() stop stop_logs() ); }
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".
$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 $@; }
Any suggestions on how to fix this || other methods that would work better are greatly appreaciated. Thanks, Thoth

In reply to Trying to simulate a CLI using hashes... by thoth

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.