Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Re: Document maintenance script

by blacksmith (Hermit)
on Jun 21, 2001 at 18:31 UTC ( [id://90368]=note: print w/replies, xml ) Need Help??


in reply to Re: Document maintenance script
in thread Document maintenance script

Thanks for the questions. Really helps me to think about what I am really doing with this script. For the answer to number one : I pride myself as someone who can give a valid reason within a timely manner for any thing that I do. This is one of those times that I am not very proud. The file is (or should be) empty when the program first starts, although there must be a file out there with this name only empty. I realize that there will be an initial 6 minute wait before the first file is copied to any of the other folders, but in the environment that this is running it will not be a huge concern. I do of course realize that as a programmer of Perl (if I would even go that far since I am so green to Perl) I should be trying to be as efficient as possible. I plan on looking into this in the near future. For answer number two : The only reason I actually have for doing this is due to my inexperience with Perl. I made the different files so that I could watch if my program was picking up the info and how it was reading it. I am sure as I get more hours under my belt I will trust my own programs enough not to rely on this. The program does work for me fine otherwise. I would like to go back through and revise the program but for now I am working on another project that has me slightly stumped and needs to be completed so it can be put into production immediately. Thanks again for the thought provoking questions and have a good day. Blacksmith.

Replies are listed 'Best First'.
Re: Document maintenance script
by CharlesClarkson (Curate) on Jun 25, 2001 at 07:41 UTC

    Could you try running this and let me know if it functions properly. I combined a few subs and eliminated the delete sub. But I wasn't sure how to test it.

    #!/usr/bin/perl use strict; use warnings; use File::Copy; sub copy_from_root { my $ftp_dir = shift; opendir my $dir, $ftp_dir or die "Cannot open $ftp_dir: $!"; my %short_names; for my $file_name (grep /\.(?:txt|doc|mpd|mta)$/i, readdir $dir) { my $daym = (localtime)[3]; my @dirs = ("c:/afis3too/$daym", 'c:/scripts/attempt', 'c:/rep +orts'); print $file_name; chomp $file_name; my $source = "$ftp_dir/$file_name"; $short_names{sprintf('%.6s.bat', lc $file_name)}++; if ($file_name =~ /^(?:afinv|csinv|sfinv)/i) { s/\.mta$/\.mpd/i; push @dirs, 'c:/invoice'; } elsif ($file_name =~ /\.doc$/i) { s/doc$/txt/ig; } elsif ($file_name =~ /\.mta$/i) { s/mta$/mpd/ig; } foreach my $dir (@dirs){ copy($source, "$dir/$file_name") or die "Cannot copy $dir/$file_name: $!"; } unlink $source or die "Cannot unlink $source: $!"; } return keys %short_names; } sub batch_files { my $batch_dir = shift; opendir my $dir, $batch_dir or die "Cannot open $batch_dir: $!"; my @files = grep /\.bat$/i, readdir $dir; return \@files; } sub run_the_batches { my ($short_names, $batch_files, $dir) = @_; my @matches; foreach my $short_name (@$short_names){ push @matches, grep /$short_name$/i, @$batch_files; print "Working...\n"; } system("$dir/$_") for @matches; } my $ftp_dir = 'c:/ftproot'; my $report_dir = 'c:/reports'; print "\n\n\n"; print " Robco Inc. Presents : \n\n\n"; print " The NEW, AMAZING, INCREDIBLE ....\n\n\n"; print " Robco Document Rotisserie!!!!!\n\n\n"; print "Just RENDER it, THEN don't REMEMBER it!!!!!\n\n"; print " It's just that easy.\n\n\n\n\n"; while (1) { print localtime, "\n"; print "sleeping .... ZzZzZzZzZz......\n"; sleep (10); print "OK! OK! .... I'm awake! .... I'm awake\n"; my $short_names = copy_from_root($ftp_dir); my $batch_files = batch_files($report_dir); run_the_batches($short_names, $batch_files, $report_dir); }

    As mentioned above, I am unsure how to test all my changes. I'm sure there's a glitch or two.


    HTH,
    Charles K. Clarkson

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-04-24 11:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found