sudharsan501:

Here are some suggestions:

I've put most of my suggestions into your code, shown below. Note: I didn't run it--tuning it up is left as an exercise for the reader...

use strict; use warnings; use File::Copy; use Date::Manip; my $search_in="U:\\Temp"; my $search_local="D:\\my"; my $copy_to=$ARGV[1]; $db_name=$db_date=$ARGV[0]; $db_name =~ s/\d|\.trn|\_backup_//g; $db_date =~s/[^\d]//g; $miss_file_date = UnixDate(DateCalc(ParseDate($db_date), "-10 minutes" +), "%Q%H%M"); $missing_file=$db_name."_backup_".$miss_file_date.".trn"; print "\n\nThe database name is: $db_name\n"; print "Error occured in file[input file] :$ARGV[0] \n"; print "File missing for date: $miss_file_date\n"; print "\nThe missing file is: $missing_file\n\n"; print "Searching..please wait\n"; perform_search($search_local, "local"); perform_search($search_in, ""); sub perform_search { my $search_dir = shift; my $local_flag = shift; foreach ( glob("$search_dir/$missing_file") ){ if (-e $_) { copy ($_,$copy_to) or print "Can't copy file to $curr_fold +er\n" and die; print "\nFile found!!\n"; print "File found in $search_in\n"; print "\nThe missing file $missing_file is copied to $copy +_to\n"; } else{ print "local search\n" if $local_flag eq "local"; print "Unable to find the missing file $_\n"; if ($local_flag eq "local") { print "Search in sql\n"; last; } } } }

You'll notice that I used a flag to let the subroutine work in two different ways, depending on whether it was local or not. I don't know if the last statement is really necessary or not, so I left it in.

...roboticus


In reply to Re: Search for a missing file..iss my script correct? by roboticus
in thread Search for a missing file..iss my script correct? by sudharsan501

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.