sub cleanthefile { my @filehandles; my ( $sourcefile, $removeq, $tempfile ) = @filehandles; # Keep a dedicated backup of CC_print.printers if (-e "/root/CC_print.printers.bkp" ) { `cp -R $filehandles[1] $filehandles[2]`; # create a temporary file if (-T ne "$filehandles[2]") { system("touch /u/ccsys/CC_print.printers.tmp"); } # extract lines from $sourcefile which do NOT have the string to remove # note that the \' inserts ticks so that strings with spaces can work, too if ( -T "$filehandles[2]") { # system ("cat $sourcefile \| grep -v $removeq $sourcefile > $tempfile"); `grep -v $filehandles[0] $filehandles[1] /dev/null /dev/null > $filehandles[2]`; sleep 1; print "Waiting to unlink..\n"; # delete source file, then rename working file unlink($filehandles[1]); rename( $filehandles[2], $filehandles[1] ); system("rm -rf $filehandles[2]"); } } else { system("touch /u/ccsys/CC_print.printers.bkp"); system("cp -R $filehandles[1] /root/CC_print.printer.bkp"); print "Please re-run the program, had to create a backup\n"; } }