Blessings upon ye monks!

I've recently run across this error message:

Use of uninitialized value in join or string at /usr/lib64/perl5/5.8.8 +/x86_64-linux-thread-multi/File/Spec/ line 81

Which wouldn't be a big deal if I were actually using File::Spec in my own code.

Long story short, I found my own bug and I've written a patch for File::Spec::Unix that makes it generate a useful error instead of the one above.

My solution was to use Carp and cluck if conditions would cause the situation above.

So, my request from ye monks is any feedback on my solution and patch before I mail it off the author.


UPDATE: I've changed the patch. The old version clucked if there were no args, the new version clucks if @_ contains an undef. IE something that exists but is not defined, EG catdir('/home',undef,'wibble')

--- lib.old/File/Spec/ 2008-02-11 19:43:20.000000000 -0800 +++ lib/File/Spec/ 2008-08-08 16:15:55.000000000 -0700 @@ -1,6 +1,7 @@ package File::Spec::Unix; use strict; +use Carp qw(cluck); use vars qw($VERSION); $VERSION = '3.2701'; @@ -78,7 +79,12 @@ sub catdir { my $self = shift; - + for ( @_ ) { + if ( !defined($_) ) { + cluck "Undefined arg passed to catdir"; + last; + } + } $self->canonpath(join('/', @_, '')); # '' because need a trailing + '/' } @@ -91,6 +97,11 @@ sub catfile { my $self = shift; + for ( @_ ) { + if ( !defined($_) ) { + cluck "Undefined arg passed to catfile"; + last; + } my $file = $self->canonpath(pop @_); return $file unless @_; my $dir = $self->catdir(@_);

Replies are listed 'Best First'.
Re: File::Spec patch (alternative)
by tye (Sage) on Aug 09, 2008 at 05:56 UTC

    Next time you have this kind of problem, consider this technique instead:

    require Carp; $SIG{__WARN__} = sub { Carp::cluck(@_) };

    It will save you a lot of time trying to patch your copy of a module.

    You can also just start your script with "perl -d" then "c" since "o warn=1" is the default which means that you'll get a stack dump tacked on to each warning you get. You can probably even get the debugger to stop at the point of the warning so that you can look around and figure out the source of the problem:

    perl -d ... > $SIG{__WARN__} = sub { $DB::single = 1; } > c

    - tye        


      I'm going to print this out in huge letters and tape it to my wall. I'm going to hire a shadowy firm in Russia to email this advice to 3 million random strangers. I'm going to hack the web page of the 2008 Olympics and put this up in it's place.

      Indeed, it could be said that I find it helpful.

Re: File::Spec patch
by parv (Vicar) on Aug 08, 2008 at 23:40 UTC
    I wonder, admittedly out loud, just how many similar patches you are going to produce.

      Me too.