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

Dear Monks, This program reads line by line and grabs the path out of the line example : H:\abc\1234\12334.090 This is a map drive from a server. If I run this program and make it grab files out of the local drive. it works fine. However if I run this program and make it grab files out of a network drive. it desn't work. it gives me an error "undefined variable in line 25" here is a sample of the file:
028749|0011960|999-99-9999|GREER|SHELDON|5/23/2003|abcd|ABDEL-WAHAB, M +AY|ABDEL-WAHAB, MAY|abcde/PHYSICIAN/WEEKLY PROGRESS NOTE|A2901006|6/5 +/2003|H:\APPS\abcde\DB\ESCRIBE\13\00004FE5.008
Do you have any ideas why it gives me an error when trying to run against a network drive versus a local drive? I have seen this problem before but I cannot find the article... Someone report it this problem on this web site... Here is my code:
#! perl -w use strict; use File::Copy; my $infile = "C:/RADTRANS/doclist.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; print "$dir\n"; 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:\\RADTRANS\\$newfile" ) or die "Failed to copy $file: $!\n"; } }

Replies are listed 'Best First'.
Re: Cannot Copy from a network drive
by waswas-fng (Curate) on Jun 07, 2003 at 01:38 UTC
    print "$dir\n"; my $dir = join "\\", @path[0,1,2,3,4,5,6];
    Looks to me like you are using $dir before you create it. Also what happens if you hit a directory like:
    h:\one\two\three\for\five\six\seven\eight
    with your script? do you mean to truncate at that point?

    -Waswas
Re: Cannot Copy from a network drive
by Aristotle (Chancellor) on Jun 07, 2003 at 00:23 UTC
    According to the code you posted line 25 appears to be
    my @path = split /\\/, $path_str;
    I'm at a loss at how this could be causing any problems considering you're checking $path_str on the previous line.

    Makeshifts last the longest.