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

Is this where (if you uncommented the print statement) you are getting the "Uninitialized value in concatenation..." error:
( $dir, $file ) = m/(.*)[\\\/](.+)/ ? ( $1, $2 ) : ( undef, $_ ); # print "$file is in the directory $dir\n"; $fileinfo[$i] = [$file, $dir];
If so, it's probably because $dir is getting set to undef, and then you are using it in string interpolation in the print statement.

Also, later that undef value could be causing problems in this code fragment:

$refarray1 = $fileinfo[$c]; if (${$refarray1}[0] eq $intersect) { print "File: ${$refarray1}[0] in directory ${$refarray1}[1]\n"; $matchedfiles[$i] = [${$refarray1}[0], ${$refarray1}[1]]; }
The expression ${$refarray1}[1] refers to the dir component of your fileinfo structure, so if it is undef, the print statement in this fragment will also generate the same error message.

Also, don't you want to increment $i in this loop?

$matchedfiles[$i++] = [${$refarray1}[0], ${$refarray1}[1]];
In general it's easier to use push: push(@matchedfiles, [ ... ]);

Update: Here are some style pointers that might make things a little cleaner.

1) Read the md5 info into a hash:

my %md5_of_known_bad; foreach $md5data (@knownbad) { ... $md5_known_bad{$filename} = $md5hash; }
This serves two purposes: it stores the md5hash of a known bad file and it also can be used to determine if a file is a bad file by using exists:
if (exists $md5_of_known_bad{$filename}) { # $filename is a known bad }

2) Your intersection logic can then be simplified to:

my @uniq; @uniq = grep { exists $md5_of_known_bad{$_} } @sysfiles;

Replies are listed 'Best First'.
Re^2: Uninitialized value in concatenation (.) or string?
by jbush82 (Novice) on May 09, 2008 at 16:29 UTC
    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.
      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?