HP3000-L Archives

February 2003, Week 4

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Ken Hirsch <[log in to unmask]>
Reply To:
Ken Hirsch <[log in to unmask]>
Date:
Wed, 26 Feb 2003 15:25:00 -0500
Content-Type:
text/plain
Parts/Attachments:
text/plain (35 lines)
From: "Johnson, Tracy" <[log in to unmask]>
>Does anyone know of or have a program that
>can print all upper and lowercase permutations
>of a string?
#!perl -w

listall(join " ", @ARGV);

sub listone {
  print $_[0], "\n";
}

sub listall {
  enumerall(\&listone, "", $_[0])
}

sub enumerall  {
  my ($sub, $sofar, $rest) = @_;
  if (length($rest) == 0) {
    &$sub($sofar);
  } else {
    my $nextchar = substr($rest, 0, 1);
    $rest = substr($rest, 1);
    if (uc($nextchar) eq lc($nextchar)) {
      enumerall($sub, $sofar . $nextchar, $rest);
    } else {
      enumerall($sub, $sofar . uc($nextchar), $rest);
      enumerall($sub, $sofar . lc($nextchar), $rest);
    }
  }
}

* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *

ATOM RSS1 RSS2