#!/usr/local/bin/perl -w
###########################################
# symlinkdir - Resolve a symlink and print
#   the target's directory.
# Mike Schilli, 2011 (m@perlmeister.com)
###########################################
use strict;
use File::Basename;

my($link) = @ARGV;

die "No link specified" unless $link;
die "$link not a symbolic link" 
  unless -l $link;

while(-l $link) {
  $link = readlink($link);
}

$link = dirname($link) unless -d $link;
print "$link\n";
