The script worked fine, and moved all of the files into the right directories (and created the directories if they didn't exist) but along the way I ran into some errors that I can't explain. Specifically, some null lines seem to have infested my DATA section...
After changing the names to protect the innocent, this is the script I'm using:
The script produces the following output:#!/usr/bin/perl use strict; use warnings; my $base_dir = "C:/Documents/perl"; while (my $line = <DATA>) { chomp $line; next if $line =~ /^\s*\#/; # next if not $line; my ($filename, $filepath) = split '\t', $line; if (not -d "$base_dir/$filepath") { system "c:/cygwin/bin/mkdir -p $base_dir/$filepath"; print "Made $base_dir/$filepath\n"; } if (not $filename) { warn "Filename is blank, filepath is [$filepath], line is [$li +ne]\n"; } else { system "mv $base_dir/$filename.xls $base_dir/$filepath"; print "Moved $base_dir/$filename.xls to $base_dir/$filepath\n" +; } print "\n"; } __DATA__ filename1 some/file/path filename2 some/other/file/path filename3 yet/another/file/path/oooh/this/one/is/long
Made C:/Documents/perl/some/file/path Moved C:/Documents/perl/filename1.xls to C:/Documents/perl/some/file/p +ath Use of uninitialized value in concatenation (.) or string at C:\Docume +nts\perl\try.pl line 15, <DATA> line 2. Use of uninitialized value in concatenation (.) or string at C:\Docume +nts\perl\try.pl line 21, <DATA> line 2. Filename is blank, filepath is [], line is [] Made C:/Documents/perl/some/other/file/path Moved C:/Documents/perl/filename2.xls to C:/Documents/perl/some/other/ +file/path Use of uninitialized value in concatenation (.) or string at C:\Docume +nts\perl\try.pl line 15, <DATA> line 4. Use of uninitialized value in concatenation (.) or string at C:\Docume +nts\perl\try.pl line 21, <DATA> line 4. Filename is blank, filepath is [], line is [] Made C:/Documents/perl/yet/another/file/path/oooh/this/one/is/long Moved C:/Documents/perl/filename3.xls to C:/Documents/perl/yet/another +/file/path/oooh/this/one/is/long
Note that I can easily fix this behavior by uncommenting the next if not $line part. The question is not how to avoid this error, the question is why it's happening in the first place.
All of the lines are read, and I don't see anything in the script that would cause me to read another line. I don't recall seeing this sort of behavior before, but I do normally include the check against empty lines.
What simple thing am I overlooking here? I SuperSearched for "__DATA__ null" as well as "__DATA__ empty" with no promising results. I've spent too much time trying to diagnose this problem, though, so I'm throwing in the towel and asking for ideas or information.
(by the way, "This is perl, v5.8.7 built for MSWin32-x86-multi-thread")
Update: I don't see the same behavior on my Mac (running OS X 10.4.1). "This is perl, v5.8.6 built for darwin-thread-multi-2level" So I'm totally baffled.
In reply to odd behavior with DATA section by Nkuvu
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |