Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to replace a module using perl command line mode. But I am getting the following warning when I run shell(csh or sh).
"Can't do inplace edit: . is not a regular file."
my shell script is
find . -name "*.c" > tomodify.txt if [ -s tomodify.txt ] then cat tomodify.txt | xargs perl -pi.bak -e 's/name1/name2/' $1 fi
Ofcourse the above script does the job, getting a bakup file after substitution, but I am getting the above said warning. I tried with -X option to avoid warnings, but no use. It runs at the shell $ prompt or % prompt. But if I run the shell script, I get the above warnings. I did search on inplace edit, but could not get a remedy. I am running on Sun solaris unix.
Can you pl. help me?
Thanks Ashok

Replies are listed 'Best First'.
Re: inplace edit
by archon (Monk) on Mar 21, 2001 at 05:14 UTC
    I'm guessing the problem is the $1 in your xargs command. xargs will automatically put the contents of the file as the arguments for you. You don't need the $1 which likely contains the offending '.'.

    Try this instead:

    find . -name '*.c' -exec perl -pi.bak -e 's/name1/name2' {} \;
    If you wanted it all in perl, you could use the File::Find module after a simple find2perl.