Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Or even more easily generated choices:
    foreach my $cmd (keys %choices) {
      for my $i (1..length $cmd) {
        $choices{substr($cmd, 0, $i)} = $choices{$cmd};
    N, NO, NOR, NORT, NORTH....


    • Or, rather than filling the hash with small keys, make a smarter dispatcher:

      # find those commands which could match
      @cmd = grep { /^$cmd/ } keys %cmd;
      # die if none or several commands match
      die "Ambiguous command $cmd (@cmd)" if @cmd != 1;
      # call the routine

      Mmm, $cmd, @cmd and %cmd used in 3 lines... That's one point in the Perl purity test. :-)