On 08/28/2006 08:37 AM, Derek B. Smith wrote:
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. [...]

So instead of doing the code below because the subdirs are unique but all log file names are the same, log.\d+, I want to use a hash table to decide what log files to copy where based on the subdir names or 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);
  }
} }


This was the only code in your post that I was able to understand because I wasn't able to figure out what words_to_num() was supposed to do. Here are two ways to go about something like what you want to do:

################################
# This is ultra-simple and doesn't do
# what you want.

if (@NBlogs2) {
  for my $log (@NBlogs2) {
    if ($log =~ m{([[:alpha:]]+)/log.\d+}) {
      my $word = $1;
      qx(echo cp $log $oldir/$word);
    }
  }
}

################################
# This might come closer to what you want.

foreach my $log (@NBlogs2) {
  if ($log =~ m{([[:alpha:]]+)/log.\d+}) {
    my $word = $1;
    my $number = $subdir_for{$word};
    qx(echo cp $log $oldir/$number);
  }
}

I decided to echo the command rather than to execute it. ALL CODE UNTESTED.

thank you
derek


You're welcome.



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to