develooper Front page | perl.perl5.porters | Postings from September 2003

Re: [perl #24000] perl -pi -e s:foo:foo2: FILE mishandles symlinks?

Thread Previous | Thread Next
Pekka Savola
September 23, 2003 09:39
Re: [perl #24000] perl -pi -e s:foo:foo2: FILE mishandles symlinks?
Message ID:
On 23 Sep 2003, Rafael Garcia-Suarez wrote:
> Pekka Savola (via RT) wrote:
> > On Red Hat Linux 7.3 and 9 (perl 5.6.1 and 5.8, respectively), at least, 
> > perl seems to be *seriously* mishandling symlinks with structures like 
> > "perl -pi -e s:foo:foo2: FILE".  If FILE is a symlink, perl doesn't follow 
> > it, causing a symlink being converted to a file in the directory where the 
> > symlink resided in.
> At first sight, I don't think perl should transparently follow symlinks.
> That's not what I expect it to do. However this can be argued.

I have to really, really disagree with you here.  Consider what the script 
is supposed to be doing: "replace test with textx in the file".  How is 
this different e.g. from firing up *any* text editor and making that 
replacement?  When I make operations on the symlink, I certainly _expect_ 
them to be done at the file the symlink points to.  This perl behaviour 
breaks the principle of least surprise badly, IMHO.

> Note that you can force perl to follow symlinks by inserting at the top
> of your script :
>     BEGIN { @ARGV = map { -l $_ ? readlink : $_ } @ARGV; }
> [You could even put this in a file, to be loaded via
> "PERL5OPT=-IFollowSymlinks".]

.. right but this is really a bit too complex, and won't help those whose 
expectations are broken by current behaviour.  However, I could imagine 
that a perl command-line argument could be possible, even though not 
really the optimal way to solve the problem.

Pekka Savola                 "You each name yourselves king, yet the
Netcore Oy                    kingdom bleeds."
Systems. Networks. Security. -- George R.R. Martin: A Clash of Kings

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About