in reply to clobbering output

perl -i"*.bak" -p -e"s/^(#!.*)/$1\n##(c)2008 by me/" change_this_file

P.S.: I use Windows, hence the double quotes.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Replies are listed 'Best First'.
Re^2: clobbering output
by QM (Parson) on Feb 24, 2008 at 22:43 UTC
    This meets the problem statement, no question.

    But I have an issue with the problem statement itself. I don't use a real shebang line. Instead, my "shebang" line is this instead:

    eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}' && eval 'exec perl -w -S $0 $argv:q' if 0; # The above invocation finds perl in the path, wherever it may be
    So fortunately the original problem statement doesn't break it, nor does the intended solution do what it's supposed to.

    This probably isn't the place to discuss the merits of a real shebang line, but I'll mention one point anyway. My *nix home directory is automounted on countless network machines, and I don't have the time to manage $PATH on every one, etc.

    Unless there is a more elegant way than this, I'll do without a shebang.

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of