title: Creating a script to delete old log files, that allows me to pass directory/age/regex arguments
body: <p>I'm trying to create a PERL script to delete old log files. One of the key things I want the script to be able to do is allow me to pass arguments for directory, name of the file (such as test.log-*), and age of the file.</p>
  
  <p>It's been a while since I've used PERL and I'm not that great anyway, so I'd appreciate some help. I'm also not terribly familiar with the getopt::long module. Here's what I'm thinking so far, and while I'm sure it's not correct, please give me any feedback that might assist.</p>
  
  <p>I want to run the script along the lines of "script.pl --dir /release/logs --type test.log-* --days 7"</p>
  
  <pre><code>#!/usr/perl
  
  use strict;
  use warnings;
  use Data::Dumper;
  use Getopt::Long;
  
  my $file;
  my ($dir,$type,$days);
  GetOptions( 'dir'   =&gt; \$dir,
              'type'  =&gt; \$type,
              'days'  =&gt; \$days);
  
  foreach my $file (&lt;$dir/$type&gt;){
     if (-M $file &lt; $days) {
         print "\n Deleting log more than '$days' old:".$file;
         unlink $file;
         # or die "\n Failed to remove $file";
     }
  }
  
  exit;
  </code></pre>