kurt2439 has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to figure out whether there is a matching folder under a different part of the directory tree and then whether there is a .pdf file in that folder. The "ALLFILES" contains pdf files (a resource fork from OSX and the "real" file). I have not cleaned up the ALLFILES to include just 1 copy of the file, but you can see below I get different results for each even though they data I am stripping from the files paths is the same. Am I not understanding something about the glob function in perl? I very rarely use perl or program so forgive me
#!/usr/bin/perl use File::Glob qw(:globally :nocase); my $PROGDIR = "/home/jchase/espresso/"; my $ALLFILES = "$PROGDIR"."ALL.txt"; my $INELIGIBLE = "$PROGDIR"."INELIGIBLE.txt"; my $INELIGIBLE_NO_FOLDER = "$PROGDIR"."INELIGIBLE_NO_FOLDER.txt"; my $INELIGIBLE_NO_PDF = "$PROGDIR"."INELIGIBLE_NO_PDF.txt"; my $ELIGIBLE = "$PROGDIR"."ELIGIBLE.txt"; my $DEBUG = "$PROGDIR"."DEBUG.txt"; #Open the eligible file list open(FILE, "$ALLFILES") or die("Error reading $ALLFILES."); #Open this file for debug information open(DEBUG, ">>$DEBUG") or die("Error reading #DEBUG."); #Loop through the eligible file list and determine if there is a #matching folder in the INTERIORS archive folder structure while ( ! eof(FILE) ) { $FULLNAME = readline( *FILE ); print DEBUG "Working with $FULLNAME"; #Split the array on the folder levels via "/" @FULLARRAY = split(/\//,$FULLNAME); #Recontrsuct the folder name while substituting COVERS archive #into INTERIORS archive. This is to find out if that folder ex +ists $INTERIORNAME = "/".$FULLARRAY[1]."/".$FULLARRAY[2]."/"."INTER +IORS archive"."/".$FULLARRAY[4]."/".$FULLARRAY[5]."/"; print DEBUG "Looking for $INTERIORNAME\n"; if ( ! -d "$INTERIORNAME" ) { open(LOG,">>$INELIGIBLE_NO_FOLDER") or die("Error reading $INELIGIBLE_NO_FOLDER"); print DEBUG "Did not find folder! Printing to Ineligib +le_no_folder\n\n"; print LOG "$FULLNAME"."\n"; close LOG; } else { print DEBUG "Found the folder, is there a PDF?\n"; #Time to find out if there is a PDF in the folder if ( ! -e <"$INTERIORNAME"*.pdf> ) { open(NOPDF,">>$INELIGIBLE_NO_PDF") or die ("Error reading $INELIGIBLE_NO_PDF +"); print DEBUG "There is no PDF in here! Printing + to Ineligible_no_pdf\n\n"; print NOPDF "$INTERIORNAME"."\n"; close NOPDF; } else { open(ELIG,">>$ELIGIBLE") or die ("Error reading $ELIGIBLE"); print DEBUG "FOUND A PDF! Printing to ELIGIBLE +!\n\n"; print ELIG "$INTERIORNAME"."\n"; close ELIG; } } } close(FILE);
And here is some DEBUG output that shows why this isn't working and I am confused. Basically the ._*.pdf file will give the correct output and the "real" file evaluation will never find a pdf. The folder check always works correctly:
Working with /local/Macintosh/COVERS archive/A-E/Alchemists Mediums and Magicians-PB/._Alchemists Mediums Magicians.pdf
Looking for /local/Macintosh/INTERIORS archive/A-E/Alchemists Mediums and Magicians-PB/
Found the folder, is there a PDF?
FOUND A PDF! Printing to ELIGIBLE!
Working with /local/Macintosh/COVERS archive/A-E/Alchemists Mediums and Magicians-PB/Alchemists Mediums Magicians.pdf
Looking for /local/Macintosh/INTERIORS archive/A-E/Alchemists Mediums and Magicians-PB/
Found the folder, is there a PDF?
There is no PDF in here! Printing to Ineligible_no_pdf
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: trouble with glob
by Marshall (Canon) on Dec 03, 2010 at 14:37 UTC | |
|
Re: trouble with glob
by kcott (Archbishop) on Dec 03, 2010 at 14:32 UTC | |
|
Re: trouble with glob
by Gulliver (Monk) on Dec 03, 2010 at 15:07 UTC | |
by Gulliver (Monk) on Dec 03, 2010 at 15:10 UTC | |
by kurt2439 (Sexton) on Dec 03, 2010 at 19:36 UTC | |
by Gulliver (Monk) on Dec 03, 2010 at 22:02 UTC | |
by Anonymous Monk on Dec 03, 2010 at 23:01 UTC | |
by kurt2439 (Sexton) on Dec 03, 2010 at 23:05 UTC | |
|
Re: trouble with glob
by kurt2439 (Sexton) on Dec 03, 2010 at 18:16 UTC | |
|
Re: trouble with glob
by Gulliver (Monk) on Apr 27, 2011 at 22:34 UTC |