Something that's relatively simple is to have a hash, with the keys being the command, and the values being anonymous subroutines.

my %command= ( shutdown => sub { print "Shutting down...\n"; exit 0; }, lock_user => sub { my ($user) = @_; # Insert code to lock $user here. }, unlock_user => sub { my ($user) = @_; # Insert code here to unlock $user }, show => sub { # Insert show code here }, lock => sub { $_ = shift; if ($command{lock_$_}) { $command{lock_$_}->(@_); } else { die "Don't know how to lock $_\n"; } }, unlock => sub { $_ = shift; if ($command{unlock_$_}) { $command{unlock_$_}->(@_); } else { die "Don't know how to unlock $_\n"; } }, help => sub {# update per L~R's suggestion: print "Current commands: "; print join "\n", sort { $a cmp $b } keys %command; }, ); my ($cmd, @args) = @ARGV; # Or however you get them. $cmd = lc $cmd; # Force lowercase per L~R's suggestion. my $sub = $command{$cmd}; $sub = $command{help} if not defined $sub; $sub->(@args);

$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/

In reply to Re: simpliest way to add "language" to my app by jonadab
in thread simpliest way to add "language" to my app by smackdab

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.