Hi please be gentle, I am very new at PERL. I am working on a script that will copy files and subdirectory within a directory into another directory on same server. I know it's weird and perhaps even dumb... but it's something I've been trying to figure out for my little site. Below are my messy code, it works, but it does not copy and replace the subdirectory files... Thanks ahead!
- Meg
#!/usr/local/bin/perl
#simple file replacement in perl
#looks for pages that are less than 2 min old and replaces
#
use strict;
use File::Copy;
use File::Find;
my $age;
my $destination="/usr/local/netscape/server4/nes/publishdocs/press2/";
my $sourcedir="/usr/local/netscape/server4/nes/publishdocs/press/";
my @files=`cd $sourcedir && ls`;
my @dirlist=readdir(DIR);
# iterate and copy each one
sub cpnewest {
copy("$sourcedir$_","$destination$_");
}
foreach (@files, @dirlist){
chomp;
# get the age in seconds
$age = (time() - (stat($sourcedir.$_))[9]);
# if we files needs to be printed in unix
print "\n$sourcedir.$_ is is $age seconds old\n";
if($age<120){
find(\&cpnewest, @dirlist);
}
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.