All,
I am trying to run logic that will copy/delete 3
versions of log.\d+ files to their respective
directories. Because there are so many directories, I
have built a hash table instead of using a bunch of
"if else conditions" with reg exps. My problem is it
is not returning the words_num translation.
BEGIN CODE
foreach my $log (@twoweekdir_contents) {
$NBlogs2[$i++] =
$log if ($log =~
/bpcd\/log|bpdbm\/log|bptm\/log.\d+/);
}
## array elements look like log.6563 ##
##-- Build a hash look-up table for subdirs --##
my %subdir_for = (
'admin' => 0, 'bp' => 1,
'bparchive' => 2,
'bpbackup' => 3, 'bpbkar' => 4,
'bpbrm' => 5,
'bpbrmds' => 6, 'bpbrmvlt' => 7,
'bpcd' => 8,
'bpcompatd' => 9, 'bpcoord' => 10,
'bpdb2' => 11,
'bpdbjobs' => 12, 'bpdbm' => 13,
'bpdbsbdb2' => 14,
'bpdbsbora' => 15, 'bpdm' => 16,
'bpdynamicclient' => 17,
'bpfilter' => 18, 'bpfis' => 19,
'bpfsmap' => 20,
'bphdb' => 21, 'bpinst' => 22,
'bpjava-msvc' => 23,
'bpjava-susvc' => 24, 'bpjava-usvc' => 25,
'bpjobd' => 26,
'bpkeyutil' => 27, 'bplist' => 28,
'bpmount' => 29,
'bpnbat' => 30, 'bporaexp' => 31,
'bporaimp' => 32,
'bporaimp64' => 33, 'bppfi' => 34,
'bprd' => 35,
'bprestore' => 36, 'bpsched' => 37,
'bpsynth' => 38,
'bptm' => 39, 'dbclient' => 40,
'infxbsa' => 41,
'mtfrd' => 42, 'nbpushdata' => 43,
'nbvault' => 44,
'sybackup' => 45, 'symlogs' => 46,
'tar' => 47,
'vault' => 48, 'vnetd' => 49,
'vopied' => 50,
'bporaexp64' => 51, 'mklogdir' => 52,
);
sub words_to_num {
my $words = @_;
##-- Treat each sequence of non-whitespace as a
word --##
my @words = split /\s+/, $words;
##-- Translate each word to its appropriate
number --##
my $num = q{};
foreach my $word (@words) {
my $digit = $subdir_for{lc $word};
if (defined $digit) {
$num .= $digit;
}
}
return $num;
} ##-- End routine words_to_num --##
print words_to_num('vopied admin'),"\n";
snippet {....}
So instead of doing the code below because the subdirs
are unique but all log file names are log.\d+ I want
to use a hash table and copy the log files to each
subdir based on the key/value relationship.
if (@NBlogs2) {
for my $log(@NBlogs2) {
if ($log =~ 'bpcd') {
qx(cp $log $oldir/bpcd/);
}
elsif ($log =~ 'bpdbm') {
qx(cp $log $oldir/bpdbm);
}
elsif ($log =~ 'bptm') {
qx(cp $log $oldir/bptm);
}
}
}
thank you
derek
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>