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....


    • That will only work as long as the choices are unique on the first letter.

      It would be much better to use the Text::Abbrev module (it's part of the core). It'll create unique abbreviations. Of course the code would be a little more convoluted:

      use Text::Abbrev;
      my %abbrev_choices;
      my %abbrevs = abbrev(keys %choices);
      foreach my $abbrev (keys %abbrevs) {
        $abbrev_choices{$abbrev} = $choices{$abbrevs{$abbrev}};
      %choices = %abbrev_choices;
      (or something like that - completely untested and of my hat)