in reply to Re: Uninitialized value in concatenation (.) or string?
in thread Uninitialized value in concatenation (.) or string?

I just commented out the print statement to speed up the scan of the remote system (outputting slows it down a lot).

I get the error on line 71

Use of uninitialized value in concatenation (.) or string at nfse.pl line 71.

69 print "\n\n"; 70 my $refarray3 = $matchedfiles[5]; 71 print "File: ${$refarray3}[0] in directory ${$refarray3}[1]\n";


Also, don't you want to increment $i in this loop? $matchedfiles[$i++] = [${$refarray1}[0], ${$refarray1}[1]];

Actually, I replaced $i with $c and just missed that spot when I did it. Ran the script again and I am of course having the same problem.

In general it's easier to use push: push(@matchedfiles, ... );

I attempted this using push($matchedfiles[$c], [${$refarray1}[0], ${$refarray1}[1]]);, but I received the message:
D:\Documents\network file scanner\enhanced>perl -w nfse.pl Type of arg 1 to push must be array (not array element) at nfse.pl lin +e 63, near "])" Execution of nfse.pl aborted due to compilation errors.



Thanks for your response. It is going to take me some time to figure out some of your recommendations. I'll post back once I've gone through it and hopefully got it going.

Replies are listed 'Best First'.
Re^3: Uninitialized value in concatenation (.) or string?
by pc88mxer (Vicar) on May 09, 2008 at 16:57 UTC
    Check the value of ${$refarray3}[1] for being undef:
    print "it's not defined!\n" unless defined(${$refarray3}[1]);
    If it's undef, it's because of your assignment of undef to $dir back in the while (<FILES>) {...} loop. Perhaps you can use the empty string there instead.

    Also, if you want $matchedfiles[$c] to be list of files, you need to use this syntax:

    push(@{$matchedfiles[$c]}, [...]);
    This makes $matchedfiles[$c] an array ref (i.e. @matchedfiles is an array of array refs.)
      I'm confused as to why $dir is undefined. The line:

      print "$file is in the directory $dir\n";

      Produces the output that I'm looking for, the file and the directory it is in:
      Ascent.jpg is in the directory C:\WINDOWS\Web\Wallpaper Autumn.jpg is in the directory C:\WINDOWS\Web\Wallpaper Azul.jpg is in the directory C:\WINDOWS\Web\Wallpaper Bliss.bmp is in the directory C:\WINDOWS\Web\Wallpaper Crystal.jpg is in the directory C:\WINDOWS\Web\Wallpaper Follow.jpg is in the directory C:\WINDOWS\Web\Wallpaper Friend.jpg is in the directory C:\WINDOWS\Web\Wallpaper Home.jpg is in the directory C:\WINDOWS\Web\Wallpaper Moon flower.jpg is in the directory C:\WINDOWS\Web\Wallpaper Peace.jpg is in the directory C:\WINDOWS\Web\Wallpaper Power.jpg is in the directory C:\WINDOWS\Web\Wallpaper Purple flower.jpg is in the directory C:\WINDOWS\Web\Wallpaper Radiance.jpg is in the directory C:\WINDOWS\Web\Wallpaper Red moon desert.jpg is in the directory C:\WINDOWS\Web\Wallpaper Ripple.jpg is in the directory C:\WINDOWS\Web\Wallpaper Stonehenge.jpg is in the directory C:\WINDOWS\Web\Wallpaper Tulips.jpg is in the directory C:\WINDOWS\Web\Wallpaper Vortec space.jpg is in the directory C:\WINDOWS\Web\Wallpaper
      Which is just the listing of the files and what directory they are in. If it is successfully printing output, would that not indicate that it is defined?

        The print statement will still work - an undef value will print as the empty string.

        Sorry, I mistook line 71 for a similar looking line (the one in the foreach $intersect (@uniq) loop.)

        If this is where you problem is:

        my $refarray3 = $matchedfiles[5]; print "File: ${$refarray3}[0] in directory ${$refarray3}[1]\n";
        then maybe $refarray3 is undef. How many elements are there in the @matchedfiles array?