#!/usr/bin/perl #Progam designed for searching through a dictionary file #for words of a certain length, or matching some pattern, #and then putting all words that match that pattern into #another file $infile = "dictionary.txt"; # file to convert $outfile = "finalconvert.txt"; #file to create or write to if (! open(INPUT,"<$infile") ) { print "Can't open file $infile\n"; die; } # While lines in file, process each one # Put processed lines in $line array $linecount = 0; # start index at zero $index = 0; while ($line[$linecount] = ) { chop $line[$linecount]; #remove newline character to facilitate pattern matching if(length($line[$linecount])==4) #Enter desired length of the word here { if($line[$linecount] =~ /([nalogiesk])([nalogiesk])([nalogiesk])([nalogiesk])/) #pattern to match { if( !(($1 eq $2) | ($1 eq $3) | ($1 eq $4) | ($2 eq $3) | ($2 eq $4) | ($3 eq $4) )) { #print statement below can be commented out #print " matched term: $line[$linecount]\n"; $newarray[$index] = $line[$linecount]; $index++; } else { if($line[$linecount] =~ /a.*a/) { $newarray[$index] = $line[$linecount]; $index++; } } } $linecount++; } } close INPUT; # Open file for output if (! open(OUTPUT,">$outfile") ) { print "Can't open file for output $infile\n"; die; } $keeper = 0; $arraylength = @newarray; while($keeper < $arraylength + 1) { print OUTPUT "$newarray[$keeper]\n"; # Write @line array to file $keeper++; }