in reply to Re: FindBin works differently on Fedora Core 2?
in thread FindBin works differently on Fedora Core 2?

I don't know of any File::Spec function which duplicates the FindBin behavior.
  • Comment on Re^2: FindBin works differently on Fedora Core 2?

Replies are listed 'Best First'.
Re^3: FindBin works differently on Fedora Core 2? (replace)
by tye (Sage) on Jun 08, 2004 at 14:22 UTC

    Replace

    use FindBin qw($RealBin);

    with

    use File::Spec::Functions qw( rel2abs splitpath catpath ); my $RealBin = catpath( (splitpath rel2abs($0))[0,1] );

    or

    use File::Spec::Functions qw( rel2abs ); use File::Basename qw( dirname ); my $RealBin = dirname( rel2abs($0) );

    for example. And read how perverse FindBin is.

    - tye        

      Both solution give wrong results. Suppose /tmp/foo/abc.pl and a symlink from /tmp/abc.pl -> /tmp/foo/abc.pl. Changing cwd to /tmp and call ./abc.pl.
      • With the first version I get "/tmp/".
      • With the second version I get "/tmp".
      • With FindBin I get "/tmp/foo", as expected.
      Maybe you wanted to emulate $FindBin::Bin, not $FindBin::RealBin?

        Sorry, I don't use FindBin (no one would ever guess that).

        Once again we have an example of a feature that FindBin has but doesn't bother to export in a reusable manner (expanding symbolic links).

        use File::Spec::Functions qw( rel2abs splitpath catpath ); my $RealBin = $0; for( $RealBin ) { $_ = readlink($_) while -l $_; $_ = catpath( (splitpath rel2abs($_))[0,1] ); }

        or

        use File::Spec::Functions qw( rel2abs ); use File::Basename qw( dirname ); my $RealBin = $0; $RealBin = readlink($RealBin) while -l $RealBin; $RealBin = dirname( rel2abs($RealBin) );

        and evidence that File::Spec could use some additions (realpath, basename, dirname).

        - tye        

Re:x3 FindBin works differently on Fedora Core 2?
by grinder (Bishop) on Jun 08, 2004 at 10:59 UTC

    I think PodMaster is suggesting sanitising the results of what FindBin returns with File::Spec, to obtain a canonical result, so to speak.

    - another intruder with the mooring of the heat of the Perl

      I would expect that FindBin itself returns a canonical result, as it always did.