develooper Front page | perl.perl5.porters | Postings from June 2014

[perl #122186] In place replacement command changes symbolic links into files and always touches all files

Thread Previous
From:
James E Keenan via RT
Date:
June 29, 2014 00:56
Subject:
[perl #122186] In place replacement command changes symbolic links into files and always touches all files
Message ID:
rt-4.0.18-12933-1404003409-1763.122186-15-0@perl.org
On Fri Jun 27 14:22:17 2014, yuri@rawbw.com wrote:
> perl -pi -e "s/blahblah/blah/g" * always converts symbolic links into 
> files (even when no replacement actually happens).
> 
> Another related problem is that such in place command touches all files 
> regardless of if replacement is done or not.
> 

You're getting what you asked Perl to do.

As is documented in 'perldoc perlrun', the '-i' switch "specifies that files processed by the "<>" construct are to be edited in-place. It does this by renaming the input file, opening the output file by the original name, and selecting that output file as the default for print() statements."

'perlrun' goes on to note:

"Note that because -i renames or deletes the original file before creating a new file of the same name, Unix-style soft and hard links will not be preserved."

Moreover, when you provide '*' for the files to be processed by the "<>" construct, you are saying, "Process all the files in this directory."  And since, the processing you have requested ("-pi") calls for renaming or deletion of the original files, the files are necessarily "touched."

This is Perl's documented behavior.  Such behavior dates back many years, probably to the dawn of Perl.  Are you advocating a change in that behavior?

Thank you very much.
Jim Keenan

---
via perlbug:  queue: perl5 status: new
https://rt.perl.org/Ticket/Display.html?id=122186

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About