Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!sdd.hp.com!news.cs.indiana.edu!iuvax!sahayman From: sahayman@iuvax.cs.indiana.edu (Steve Hayman) Newsgroups: comp.lang.perl Subject: Longest word composed of Unix commands Message-ID: <77888@iuvax.cs.indiana.edu> Date: 12 Dec 90 19:09:39 GMT Sender: sahayman@iuvax.cs.indiana.edu Lines: 89 Have you ever wondered what the longest word is that can be spelled with consecutive Unix commands? (i.e. "fingertip" = "finger" + "tip") You have? Well, stop worrying. Here's a script that will find them by seeing which words in /usr/dict/words can be spelled via combinations of commands in /bin:/usr/bin:/usr/ucb ok ok it's a dumb script, but how many of you knew that "testicular" can be spelled with standard Ultrix commands? I ran this on an Ultrix system and the longest words produced were watershed prescript fingertip predicate extricate flintlock printmake collinear manometric manuscript communique testicular clearheaded fingerprint don't waste too much time running this ... #!/usr/bin/perl # unixword # find the words in /usr/dict/words that can be constructed # out of unix commands. sort by length. # when I run this on our ultrix machine, the longest words I get are # manometric # manuscript # communique # testicular # clearheaded # fingerprint # # OK it's a silly script. don't waste too much time running it. # (it may take a few minutes) # steve hayman # dec 12/1990 @dirs = ( '/bin', '/usr/bin', '/usr/ucb'); $wordlist = '/usr/dict/words'; # step 1: get a list of file names in the various directories foreach $dir ( @dirs ) { opendir(DIR, $dir) || die "Can't opendir $dir: $!"; push(@files, readdir(DIR)); close(DIR); } # step 2: protect metacharacters like '.' or '[' which # can occur in the file names foreach $f ( @files ) { $f =~ s/[.[]/\\$&/g; } # step 3: construct a suitable regular expression matching # all these filenames $re = '^(' . join("|", @files) . ')+$' ; # step 4: match the dictionary file against this pattern; store words that # match the pattern - assoc. array indexed by word, containing word len. open(DICT, $wordlist) || die "Can't open $wordlist: $!"; while ( ) { chop; $len{$_} = length if /$re/io; } # step 5: print word list in order of length foreach $word ( sort lengthwise keys %len ) { print "$word\n"; } sub lengthwise { $len{$a} - $len{$b}; }