in reply to archive UNIX files
Looking at your code, I see some things that can be simplified immensely :
Pulling apart the string from localtime() and then piecing it together again is ingenious, but the POSIX module has a really useful routine, strftime(), which formats times very nicely. Other modules, like the DateTime module, also provide this.
You can replace the top part of your script by the following lines :
use POSIX; my $ext = strftime "%Y%m%d%H%M", localtime;
Your parameter parsing will allow for weird things happening if there is a file -c in your directory.
If you want to have nicer command line handling, turn to GetOpt::Long, at least I would recommend adding a second switch -- to turn off command line parameter processing and moving the command line processing out of the loop :
my $compress_files; if ($ARGV[0] eq '-c') { $compress_files = shift @ARGV; }; foreach (@ARGV) { ... };
The program does not give a reason why exactly it failed when opening / creating a file fails. This is bad.
# OPEN THE ORIGINAL FILE die "Can't open file for reading : $!\n" unless open(INFILE,"<$_"); # OPEN THE NEW FILE die "Can't open file for writing : $!\n" unless open(OUTFILE,">$arcfile");
The program won't work on Windows as you are not setting binmode and thus, the files to be copied will be truncated at the first ^Z byte encountered in the file. This is not truly much of a concern for you, as you intend your script to be running under Unix, but knowing and caring about binmode dosen't hurt :
# OPEN THE ORIGINAL FILE die "Can't open file for reading : $!\n" unless open(INFILE,"<$_"); binmode INFILE; # OPEN THE NEW FILE die "Can't open file for writing : $!\n" unless open(OUTFILE,">$arcfile"); binmode OUTFILE;
Of course, you could also use File::Copy or File::NCopy to copy the files, alleviating you from caring about these details.
Documentation in the POD is cool. Take a look at Pod::Usage to reuse that documentation for your help text.
perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web
|
|---|