title: how get the last directory using perl?
body: <p>I use below script to get the last directory. </p>
  
  <pre><code>my $bsnap = bla_path 
  my $numbsnaps = defaultstr(some_file);
  my (%snapshotdirs, $lastsnap);
  if ($numbsnaps &gt; 0) {
      system(@mkdir, '-vp', "$backupsnap/$bserver");
      exit 1 if checkrc("mkdir $backupsnap/$bserver:", $?, $!);
      unless(opendir($fh, "$backupsnap/$bserver")) {
          print STDERR "error: failed to open snapshot dir: $!\n";
          goto snapshot_end;
      }
      foreach $lastsnap (sort(grep({$_ !~ /^\.\.?$/ and -d "$backupsnap/$bserver/$_";} readdir($fh)))) {
          my $day = $lastsnap;
          $day =~ s/-\d+$//;
          push(@{$snapshotdirs{$day}}, $lastsnap);
      }
      if ($lastsnap) {
          $lastsnap = "$backupsnap/$bserver/$lastsnap";
      } else {
          $lastsnap = "$backupstore/$bserver" unless $lastsnap;
      }
      system(@mkdir, '-vp', "$bsnap");
      exit 1 if checkrc("mkdir $bsnap:", $?, $!);
  }
  </code></pre>
  
  <p>But when I print <code>$lastsnap</code> I only get <code>$backupstore/$bserver</code>. I want to get <code>$backupsnap/$bserver/$lastsnap</code>. What am I doing wrong? </p>