use Fcntl; #----------------------------( promptUser )-----------------------------# # # # FUNCTION: promptUser # # # # PURPOSE: Prompt the user for some type of input, and return the # # input back to the calling program. # # # # ARGS: $promptString - what you want to prompt the user with # # $defaultValue - (optional) a default value for the prompt # # # #-------------------------------------------------------------------------# sub promptUser { #-------------------------------------------------------------------# # two possible input arguments - $promptString, and $defaultValue # # make the input arguments local variables. # #-------------------------------------------------------------------# local($promptString,$defaultValue) = @_; #-------------------------------------------------------------------# # if there is a default value, use the first print statement; if # # no default is provided, print the second string. # #-------------------------------------------------------------------# if ($defaultValue) { print $promptString, "[", $defaultValue, "]: "; } else { print $promptString, ": "; } $| = 1; # force a flush after our print $_ = ; # get the input from STDIN (presumably the keyboard) #------------------------------------------------------------------# # remove the newline character from the end of the input the user # # gave us. # #------------------------------------------------------------------# chomp; #-----------------------------------------------------------------# # if we had a $default value, and the user gave us input, then # # return the input; if we had a default, and they gave us no # # no input, return the $defaultValue. # # # # if we did not have a default value, then just return whatever # # the user gave us. if they just hit the key, # # the calling routine will have to deal with that. # #-----------------------------------------------------------------# if (defined($defaultValue) && "$defaultValue") { return $_ ? $_ : $defaultValue; # return $_ if it has a value } else { return $_; } } #$path = "x.txt"; $path = promptUser("File to shred - "); $n = 2000000; $abc = "qwertyuiopadsfghjklzxcvbnm"; sysopen(FH, $path, O_RDWR) || die $!; $ok = ""; while (1) { $ok = promptUser("Shall I shred $path? ", "no"); exit if $ok eq "no" || $ok eq "n" || $ok eq "N"; last if ($ok eq "y" || $ok eq "Y" || $ok eq "yes"); } ($x,$x,$x,$x,$x,$x,$x,$x) = stat(FH); print "$x bytes\n"; $n = $x; for ($i=0; $i<20; $i++) { $x = ""; $j = 0; for ($j = 0 ; $j <$n; $j++) { $x = substr($abc, rand(length($abc)), 1); #$x |= 0xffff if rand(10) > 5; sysseek(FH,$j,0) || die "$!"; syswrite(FH, $x, 1) || die "$!" ; } }