in reply to Deleting corrupted perl files - modifying the perl runtime

So, what exactly identifies a corrupted file? An inserted semicolon on the third column of each line? Or just some random characters?

If you are sure that all non-corrupt perl scripts actually compile, you can write something like this on the shell:

for i in *; do perl -c "$i" || rm "$i"; done

(assuming a bash-like shell). Please make a backup first ;-)

Replies are listed 'Best First'.
Re^2: Deleting corrupted perl files - modifying the perl runtime
by Corion (Patriarch) on Jul 29, 2008 at 06:38 UTC

    Personally, I've learned to not do rm -- "$i" but to use the following idiom:

    for i in *; do perl -c "$i" || echo rm -- "$i"; done

    This allows me to inspect what would happen if I were to run the command. When I'm confident that the output is what I want, I either delete the echo from the line or pipe the whole output into another shell:

    for i in *; do perl -c "$i" || echo rm -- "$i"; done |bash

    I employ a similar technique before issuing a manual DELETE command on a database.