#!/usr/bin/perl $| = 1; $* = 1; sub usage { print STDERR "$0: @_\n" if @_; die "usage: $0 [-depth] word ...\n"; } $DEPTH = 0; $QUIET = 1; @ARGV || &usage("need more arguments"); OPT: while ($ARGV[0] =~ /^-(.*)/ && (shift, $_ = $1, 1)) { /^$/ && next OPT; /^\d+/ && do { $DEPTH = $_; next OPT; }; s/q// && do { $QUIET = 1; redo OPT; }; /d/ && do { $debug += s/d//g; redo OPT; }; &usage("Unknown option: -$_"); } for (@ARGV) { &lookup($_) } sub lookup { local ($word) = shift; local (@xrefs, $_); return if $depth > $DEPTH; $depth++; print "DEPTH IS $depth\n" if $debug; if ($seen{$word}++) { print "ALREADY SAW $word\n" if $debug; return; } push (@Words, $word); print "[LOOKUP ", join (" <- ", reverse @Words), "]\n\n" unless $QUIET; $_ = `webster $word`; print; s/\[[^]]*\]//g; if (/^Cross references:/) { local($_) = $'; substr($_, index($_, "\n\n")) = ""; @xrefs = /\s\d+\.\s+(\S+)/g; } push(@xrefs, /\b([A-Z][A-Z-]+[A-Z])\b/g); grep (tr/A-Z/a-z/, @xrefs); print "\nXREFS: ", join (", ", @xrefs), "\n\n" if $debug; for (@xrefs) { #&lookup($_) unless $seen{$_}++; &lookup($_); } pop(@Words); $depth--; }