I have a bash command, get-modified-perl-files
, that returns all the Perl files I have modified in my repository. I would like to use perltidy on all of these files.
I created a bash function to do the job:
tidy() {
for f in `get-modified-perl-files`
do
echo $f
perltidy -b $f
done
}
According to the help page of perltidy, the -b option should create a backup of my original file and modify it in-place:
-b backup original to .bak and modify file in-place
However, when I launch my bash function, no backup is created. My files are not modified, but the output of perltidy is printed on the standard output. As a consequence, I decided to change my call to perltidy that way:
\cp $f $f.bak
perltidy $f > $f
Now, when I run my command, the backup of my file is correctly done, but the original file is emptied, and the following message is displayed:
skipping file: file.pl: Zero size
I've found a workaround which gives the result I want, but it seems far-fetched:
\cp -f $f $f.bak
echo "$(perltidy $f)" > $f
Why the -b option doesn't work? Is there a way to do the same job without using this weird redirection?
EDIT: Here is my .perltidyrc
file:
--perl-best-practices
--no-standard-error-output
--closing-side-comments
--closing-side-comment-interval=10
--blanks-before-subs
--blanks-before-blocks
--maximum-line-length=130