in reply to Re^2: Following symlinks manually
in thread Following symlinks manually

A CPAN search on 'symbolic links' found File::Spec::Link in the File::Copy::Link distro:
perl -MFile::Spec::Link -le 'print File::Spec::Link->resolve_all(shift +)' foo
It returns b/foo for Tanktalus's example setup

Replies are listed 'Best First'.
Re^4: Following symlinks manually
by Tanktalus (Canon) on Jan 16, 2007 at 00:20 UTC

    A cursory glance at File::Spec::Link says it probably will work. I'll go away now to test it. Thanks. I searched CPAN, but coming up with the right search terms is always key!

    (...)

    Yes, that looks right. I think my solution is something like this:

    use File::Spec::Link; my $curlink = shift; my $linkto; while ( ($linkto = readlink($curlink)) and $linkto =~ m:^S/: ) { print "from $curlink "; $curlink = File::Spec::Link->linked($curlink); print "to $curlink\n"; } if (-l $curlink) { # do stuff with readlink($curlink) } else { # do stuff with $curlink (now a file) }
    Thanks!