Skyler99 has asked for the wisdom of the Perl Monks concerning the following question:

Monks, I run this program and it gave me an error message "Use of Uninitialize value in Join or String Line 25" Do you have any ideas on how to fix ths program?? Here is a sample data:
028749|0011960|999-99-9999|GREER|SHELDON|5/23/2003|ABCDE|ABDEL-WAHAB, +MAY|ABDEL-WAHAB, MAY|ABCDE/PHYSICIAN/WEEKLY PROGRESS NOTE|A2901006|6/ +5/2003|H:\APPS\ABCDE\DB\ABCDE\13\00004FE5.008
#! perl -w use strict; use File::Copy; my $infile = "C:/radtrans/doclisth.chr"; my ( $yr, $mo, $dy ) = (localtime)[5,4,3]; my $outfile = sprintf( "C:/radtrans/%04d%02d%02d.txt",$yr+1900,$mo+1,$ +dy ); my $staticdir = "C:\\radtrans\\"; open IN, "<$infile" or die "Couldn't open $infile, $!"; open OUT,">$outfile" or die "Couldn't open $outfile, $!"; while (<IN>) { chomp; my @fields = split /|/; my $newfile = $fields[0]; my $path_str = $fields[12]; do { warn "Empty field 13"; next } unless $path_str; my @path = split /\\/, $path_str; my $dir = join "\\", @path[ 0, 1, 2, 3, 4, 5, 6 ]; $newfile =~ s/$/.rtf/; my $out = join ('|', @fields[0..9]) . "@" . $staticdir . $newfile; print OUT "$out\n"; process_dir($dir,$newfile); } close IN; sub process_dir { my ($dir, $newfile) = @_; do { warn "$dir does not exist!\n"; return } unless -e $dir; opendir DIR, $dir or do { warn "Could not open $dir $!\n" ; return }; while ( my $file = readdir DIR ) { print "dir: $dir file:$file newfile:$newfile\n"; #before the next unless statements. next unless -f "$dir\\$file"; next unless $file =~ m/\.rtf$/i; copy( "$dir\\$file", "C:\\temp\\$newfile" ) or die "Failed to copy $file: $!\n"; } }

Replies are listed 'Best First'.
Re: Use of Uninitialize value in Join or String
by Zaxo (Archbishop) on Jun 09, 2003 at 02:44 UTC

    That is a warning, not an error. join will be happy to join undef, @foo; to the same effect as joining with an empty string.

    You can turn the warning off in modern perl with { no warnings 'uninitialized'; ... } That is lexically scoped, which is why I used a bare block there. Older perl is more awkward about switching off warnings. It is not selective and there are peculiar rules to follow. See the docs for them.

    (Added) Looking harder at your code, I suspect that some of your data is not providing array elements that you explicitly index. If so, perhaps you need to check your data parsing.

    After Compline,
    Zaxo

      Thanks for replying back. when I run the program against a local directory. It works fine but If I run it against a map drive. It doesn't work and it gave me the error message. could you tell me what could I do to rewrite my code so I read the file with no problems.?

        Just out of curiosity, are you sure the file on the map drive is in the same format as the file on the local directory?

        -- vek --