develooper Front page | perl.perl5.porters | Postings from July 2008

Re: fixing the silently failing implicit-close bug (was magic crud)

Thread Previous
From:
Ed Avis
Date:
July 30, 2008 01:05
Subject:
Re: fixing the silently failing implicit-close bug (was magic crud)
Message ID:
loom.20080730T075935-889@post.gmane.org
Ed Avis <eda <at> waniasset.com> writes:

>>>>To this day, Perl's implicit closing of files doesn't warn you of
>>>>errors, let alone exit nonzero.  This makes it do wrong thing and not
>>>>even tell you it did them wrong.

>If I might play devil's advocate for a moment:
> 
>The manual page clearly states that it ignores errors on close and always has
>done.  Here's the perl1 manpage;

Obviously, I made a mistake here: I should have quoted from perlrun(1):

                #!/usr/bin/perl 
                $extension = '.orig'; 
                LINE: while (<>) { 
                    if ($ARGV ne $oldargv) { 
                        if ($extension !~ /\*/) { 
                            $backup = $ARGV . $extension; 
                        } 
                        else { 
                            ($backup = $extension) =~ s/\*/$ARGV/g; 
                        } 
                        rename($ARGV, $backup); 
                        open(ARGVOUT, ">$ARGV"); 
                        select(ARGVOUT); 
                        $oldargv = $ARGV; 
                    } 
                    s/foo/bar/; 
                } 
                continue { 
                    print;  # this prints to original filename 
                } 
                select(STDOUT); 

The point still stands.  It's pretty 'obviously' documented that -i does not
check close().  Just as 'obvious' as that <> will sometimes go off and run
commands, overwrite things or open the wrong file.

-- 
Ed Avis <eda@waniasset.com>


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