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:

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.
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:
.\v706_7-17 .\v706_7-17/DSP-23/6DCL_Ada_Sci
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:
my $directory = "\.\/v706_7-17"; # Set directory to search
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:
./v706_7-17 ./v706_7-17/DSP-23/6DCL_Ada_Sci
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.

In reply to A Quirk in File::Find? by Larson2042

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.