Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Perl will close the old file or handle upon opening a new one. To localize FOO you can either local(*FOO) or else store your handle in a variable. With 5.6 you can use a regular variable as a handle. With 5.005 and earlier you can either
use Symbol; # Time passes my $foo = gensym(); open ($foo, "<$file") or die "Cannot read $file: $!";
If you don't want to use a module you can always do it yourself:
my $foo = do {local *FOO};

Now for more useful comments. Do as it says in perlstyle and on every open of a file, directory, etc check for errors and die with an informative message. The basic rule is avoid making errors if you can, arrange that any errors you make will be caught ASAP, and arrange that they are caught with enough information to fix the error. With your code should the code be run by a user who does not have sufficient permissions to create the directory you won't get told what the real problem is and it may take a while to even notice the problem.

And finally for this task I strongly suggest getting and installing rsync. (Search at Google if you do not have it already.) Efficiently recursively backing up directories from one spot to another, one machine to another if need be, using a variety of protocols is a solved problem. :-)


In reply to Re (tilly) 1: bag of questions... by tilly
in thread bag of questions... by kapper

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2021-12-02 15:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (22 votes). Check out past polls.

    Notices?