Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • $0 completely and utterly fails to work when you do /path/to/perl $script, sorry.
    • I can’t reproduce that.

      $ cat bin/t.pl
      #!/usr/bin/perl -l
      use File::Spec::Functions qw( rel2abs );
      print rel2abs $0;
      $ /usr/bin/perl bin/t.pl
      /home/ap/bin/t.pl

      Can you?

      • ah never mind, I can't. I was remembering a bug that got tickled in qpsmtpd by this, but I think it's because we aren't using rel2abs.
  • It's been many years since I last used FindBin, but the reason for this is not one of the reasons you describe.

    The reason for me was that FindBin just produced an error, in this case in a CGI script, because it had insufficient access rights to one of the ancestor directories (which is like a parent directory but possibly further upstream) of the directory that the script was in for some reason, FindBin seems to think it's necessary to walk the whole path.

    So even though the script worked from the co
    • just produced an error […] because it had insufficient access rights to one of the ancestor directories

      Argh! That never occured to me – just another reason to steer clear. It’s almost comical how broken FindBin is if you get down to it – it’s almost a miracle how rarely people seem to be affected by that.

  • Stealing a page from Schwern - have you filed a bug report?

    http://rt.cpan.org/Public/Dist/Display.html?Name=FindBin [cpan.org]

    • As I wrote in the comments of my other post about this [perl.org]:

      The whole point of FindBin is that if it can’t locate the script via $0 it will try to find it in the PATH […] Ripping that behaviour out 10 years after the fact doesn’t seem wise, even if the behaviour is broken for some edge cases. I’d prefer to deprecate FindBin in favour of a saner new alternative.

      • I read that, it doesn't change my position. You seem suprised that people are suprised FindBin is broken. Where is the bug supposed to be reported? In the designated place or some external forum.

        I think it is a bad precedence to suggest that we shouldn't document bugs because they have existed for a really long time and fixing them means deprecating the module entirely.

        I am not trying to be flippant or antagonistic. I just think it is unfair to expect folks to have read everything you have read.
        • I am entirely fine with a doc patch for FindBin, and if there is a better module, a deprecation notice in the FindBin docs pointing to it. That’s not “fixing” FindBin, and therefore is a good idea. I hadn’t thought of that.

  • The File::Spec::Functions solution fails to find the correct directory if $0 is a symlink whose value contains a slash. It will find the directory containing the symlink rather than the directory containing the target of the symlink. Also, on perl 5.8.2, catpath requires 3 arguments and you're only giving it 2. That can be fixed by adding a third "" argument.
    • Yes, because it purposely does not examine the file system. This should work:

      use Cwd 'abs_path';
      use File::Basename;
      use lib dirname( abs_path $0 );