On Wed, 19 Mar 2003, Ohad Ohad wrote:

> I have a link and want the real file that it is pointing to.
>
> This means also if I have a linked list of links I want to get the real file
> at the end.

That's a bit tricky, but it can be done.  You'll need to use the stat
builtin to get at the file information.  Here's an excerpt I used to find
out what a symbolic link was pointing to.  It reads in a list of
directories under a certain directory, then looks to see if there are
multiple entries (this came from the Perl Cookbook).  You'll have to
modify it for your needs, of course.  This algorithm in particular is
looking to see if a particular directory exists, which $build is compared
to later on.

        while(defined($file = readdir BW)) {
            my @stats = stat("$dir/$file");
            push(@{$seen{$stats[0], $stats[1]}}, $file);
        }

        close BW;

        foreach my $devino (sort keys %seen) {
            my ($dev, $ino) = split /$;/o, $devino;
            if(@{$seen{$devino}} > 1) {
                $build = $seen{$devino}->[1];
            }
        }

-- Brett
                                          http://www.chapelperilous.net/
------------------------------------------------------------------------
If we do not change our direction we are likely to end up where we are headed.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to