Hi YYQ,

On Fri, 16 Sep 2011 17:53:25 +0800
"y...@eisoo.com" <y...@eisoo.com> wrote:

> Hi, All:
> 
>      I want to test if a file exists or it is a link or not, the code is:
> #!/usr/bin/perl -w
> 
> use strict;
> use File::Basename;
> use File::stat;
> use Fcntl ':mode';
> 
> my $elfobj = $ARGV[0];
> 
> sub strtrim ()
> {
>      #.....
> }
> 
> sub copyfile ()
> {
>      #.....
> }
> 
> my @deps = `ldd $elfobj`;
> foreach my $lib (@deps) {
>      chomp ($lib);
>      my ($dep,$path) = split ("=>", $lib);
>      ##handle path, and it value is /lib64/ld-linux-x86-64.so.2, which 
> is a link file.
>              if (-e $path) {
>                  print $path."\n";
>              }
> }

Well, one problem I can see is that the ldd output contains whitespace before
and after the "=>", so this may trip you. To be sure what exactly is happening,
you can use the perl debugger ("perl -d") to investigate:

http://perl-begin.org/topics/debugging/

Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
First stop for Perl beginners - http://perl-begin.org/

In Soviet Russia, every time you kill a kitten, God masturbates.
    — http://linux.slashdot.org/comments.pl?sid=195378&cid=16009070

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to