in reply to Handling uninitialized values

Or if $sub_dir is always going to be empty, then why are you using it?

I am assuming that you have some kind of loop going on where $sub_dir may or may-not be assigned. In that case I would try something like:

my $path = join('', $dir, ($foo || ''), $file);
This will fail if $foo == 0 so if that is a possibility then you could use..
my $path = join('', $dir, (defined $foo ? $foo : ''), $file);

Replies are listed 'Best First'.
Re: Re: Handling uninitialized values
by blue_cowdawg (Monsignor) on May 23, 2001 at 01:01 UTC

    Very good point. If a var is going to be empty... toss it.

    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Peter L. Berghold --- Peter@Berghold.Net
    "Those who fail to learn from history are condemned to repeat it."
    
Re: Re: Handling uninitialized values
by THRAK (Monk) on May 23, 2001 at 16:12 UTC
    If you read the question again, you will see the first thing I mentioned was that this was in a loop and the value is undefined when accessing files in the root location. This was only a small snippet to illustrate the point of the question.

    -THRAK
    www.polarlava.com