#!/bin/perl # # Fish - By: Theo Van Dinter 95/11/06 # # This is a pretty useless, but interesting Perl script to overwrite a file # with random fish names. It could be modified for a 'wipeinfo' type of # program, but... # # PS: This is Version 2... Took 22 seconds to do a 130k file... # Version 1 took 1:50 ... ;) # # PS2: I've gone insane and decided to skip outside of marine critters... # ($file)=@ARGV; $out=$file; @fish=("carp","halibut","trout","salmon", "poached trout in a white wine sauce", "flounder", "mackerel", "bass", "sea bass", "guppie", "goldfish", "tuna", "angel fish", "swordfish","marlin","dead salmon","fried trout","herring", "red herring","dead herring","sole manier","dead sole", "cod","rock cod","turbot","haddock","white baith","fish", "bream","poached salmon","poached salmon in a white wine sauce", "pike","barracuda","sting ray","catfish","dogfish","jelly fish", "man o war","dolphin","whale","mako shark","shark","squid", "poodle","pork","plip!","poohead","beagle","dogbert","dilbert", "oyster","calvin and hobbes","snail","pork chop","wakko","yakko", "dot","belgium","torque","QQQQ","flux","sardines","wally","sole", "bait","minnow","penguin","gilligan","skipper","shrimp","mussel", "abalone","lobster","whitefish","one fish","two fish","red fish", "dead fish","blue fish" ); if ( $file eq "" ) # You no input filename! { print "\nNo input file specified!\n\n"; print "Usage: fish [input filename]\n\n"; exit; } # This next section can most likely (99.9%) be done more efficiently, but hey, # what do you want? I wrote the code during Diff. Eq's... It can't be PERFECT. # BTW ... It finds the length of the file in bytes (hence the reason it # says that it's finding the the size in bytes... ) open(F,"<$file") || die "Can't open the file!"; print "\nOpened $file, finding size in bytes...\n"; foreach() { $l+=length($_); } close(F); print "File closed, it's $l bytes long...\n"; srand(time|$$); # Randomize $go=1; # Initial Condition print "Fisherizing...\n"; # Blah. while($go) # Loop until words don't fit anymore. 8( { $temp=int(rand($#fish+1)); # Pick a random word. # This next section does a few different things if the random word that is # picked won't fit in the amount of space left to replace the file. if ( length($fish[$temp]) > $l-length($al) ) { foreach(@fish) # Run Through the fish array, and make a new { # one with the words that WILL fit. push(@ok,$_) if ( length($_) <= $l-length($al) ); } if ( $#ok==-1 ) # If there aren't anymore words that will { # fit, break the loop and continue. $go=0; $al=~s/,$//; # Remove the comma at the end of the line. } else { $temp=int(rand($#ok+1)); # Pick a random word that will fit. $al.=$ok[$temp]; $al.=","; $temp2+=length($ok[$temp])+1; if ( $temp2>=70 ) # If the line is >=70 chars, put a newline. { $al=~s/,$/\n/; $temp2=0; } } undef(@ok); # Remove the temporary array. } else # The randomly selected word will fit, use { # that... $al.=$fish[$temp]; $al.=","; $temp2+=length($fish[$temp])+1; if ( $temp2>=70 ) # Newline if length of line is >= 70 chars. { $al=~s/,$/\n/; $temp2=0; } } } while($l-length($al)>0) # Fill the rest of the file with newlines until { # the output buffer is the same length as the $al.="\n"; # file we're overwriting. } print "Done Fisherizing, writing output file.\n"; open(F,">$out") || die "Can't open file for writing!"; print F $al; close(F); print "Finished!\n\n"; # This is a really complex function, but I # like it... ;)