if I've done something unwise or left something amiss
You're not checking the return values of both of your file opens. This is generally a bad thing, because reading from or writing to an un-opened filehandle yields undefined behaviour. Note that if your first open fails, you'll still attempt to do the database copy. Is that desireable?

It also seems to me that you could make your file-copy section much more efficient if you considered the File::Copy module. For example:

### Back up the file, if it exists use File::Copy; if(-e $file{1}) # if the file exists { unless(copy($file{1}, $file{2})) { print "Failed to copy file: $!"; exit; # unless you want to do the copy anyway } } ### Copy the database

Alternately if you like hand-rolled solutions, consider the following:

if(-e $file{1}) # if the file exists { open FILE1, "< $file{1} or die "Failed to open $file{1}". " for reading: $!"; local $/ = ""; # prepare to read the whole # file in at once my $filecontents = <FILE1>; close FILE1; open FILE2, "> $file{2} or die "Failed to open $file{2}". " for writing: $!"; print FILE2 $filecontents; close FILE2; }
Hope that helps. :) (Oh, and note that $file1_data, or $filecontents in my example, need not be global at all.)

jarich


In reply to Re: Database backup submission by jarich
in thread Database backup submission by fireartist

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.