Larson2042 has asked for the wisdom of the Perl Monks concerning the following question:
I'm relatively new to perl, so I don't know if my problem was a bug, quirk, feature, or whatnot, but I thought I would post it here to see what more experienced monks might think.
So the point of the program is to search through a directory and pull data from text files of a certain name and then write that data to an excel file. I also want to take part of the directory for use as a worksheet name, which is where I was having my problem. The relevant code, set up to produce the error:
I'm on a windows system, which is why I set the search directory to .\v706_7-17 instead of ./v706_7-17. The debug prints gave the expected results:use warnings; use strict; use File::Find; my $directory = "\.\\v706_7-17"; # Set directory to search find(\&wanted, $directory); sub wanted { return unless -f; # Operate only on files, not directories my $curfile = $_; if ($curfile =~ m|list\$\$|i) { # If the file is a LIST$$ print "$directory\n"; # For debug purposes print "$File::Find::dir\n"; # For debug purposes $File::Find::dir =~ m|$directory\/(.*)|; # Variable way that +didn't work # $File::Find::dir =~ m|\.\\v706_7-17\/(.*)|; # Hardcoded way + that worked my $name = $1; $name =~ s|\/| |; # Replace "/" with " " for use in naming th +e worksheet ... #and on to the rest of the code.
But only the hardcoded version of the regex would find a match. Then, I tried changing the backslash to a forwardslash on the original search directory:.\v706_7-17 .\v706_7-17/DSP-23/6DCL_Ada_Sci
And I was greeted with success. The variable regex found a match and everything worked as it should. The debug printouts also gave the expected results:my $directory = "\.\/v706_7-17"; # Set directory to search
So all in all, I found the whole thing a little strange that the debug printouts would match, but the regex wouldn't work as intended with the backslash../v706_7-17 ./v706_7-17/DSP-23/6DCL_Ada_Sci
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: A Quirk in File::Find?
by ikegami (Patriarch) on Sep 23, 2009 at 21:15 UTC | |
by Larson2042 (Novice) on Sep 23, 2009 at 21:42 UTC | |
by ikegami (Patriarch) on Sep 23, 2009 at 22:11 UTC | |
|
Re: A Quirk in File::Find?
by Corion (Patriarch) on Sep 23, 2009 at 21:16 UTC |