Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: opened file being overwritten

by GrandFather (Sage)
on Dec 13, 2012 at 22:44 UTC ( #1008740=note: print w/ replies, xml ) Need Help??


in reply to opened file being overwritten

This is a good time to start always using the three parameter version of open and lexical file handles:

open my $file4In, '<', $fileName or die "Could not open $filename: $!\ +n";

Appending In or Out to your file handles helps as a sanity and consistency check.

You get even more linty goodness if you always use strictures (use strict; use warnings;).

Note too that showing why an open failed often is at least as useful as showing which open failed.

True laziness is hard work


Comment on Re: opened file being overwritten
Download Code
Re^2: opened file being overwritten
by davido (Archbishop) on Dec 13, 2012 at 23:01 UTC

    I might add that while it's uncommon to see it done here, checking the return value of print can be useful. Consider this:

    perl -e 'print BADHANDLE "Hello world.\n" or die $!'

    ...output...

    Bad file descriptor at -e line 1.

    ...which is kinda nice information to know.


    Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1008740]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (13)
As of 2015-07-06 23:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (85 votes), past polls