in reply to Re^3: Using File::DosGlob::glob in loop only works first time
in thread Using File::DosGlob::glob in loop only works first time

As anticipated above by japhy, there is an evil windows reason at work. I was getting error messages like:

File check, cannot access C:/Program\ Files/DirDictate/soap_form/soap_ +final.dot, No such file or directory
I tried preprocessing my $template_file variable with:

$template_file =~ s#/#\\\\#g;
but that didn't help and so scanning around the ActiveState archives I found:

perl-win32-users Re: using glob with filenames with spaces by Edward G. Orton, Jan 31 2002 7:08AM my @html_files = glob qq{"$input_dir/*.html"}; ego Edward G. Orton, GWN Consultants Inc. Phone: 613-764-3186, Fax: 613-764-1721
Now in this case, the glob is being processed in list context, but I didn't think of "context" when I twisted this example for my needs. The file names that I wanted to test would be several absolute path names that wouldn't all have the same directory portion. So, faced with a series of files to check for filedom, I thought that having glob take its crack at creating/passing along the filename would get me its special powers of handling pathnames that include spaces in a Windows world.

It appears that glob is acting like an iterator in which the original call to glob hangs around and gets fired with each visit to the glob line rather than new calls to glob being fired when the line repeats with the loop. I thought that perhaps wrapping an eval around my glob line would do what I wanted, but I'm rather clumsy with that command and the slice/[0] approach works quite nicely. :-)

Replies are listed 'Best First'.
Re^5: Using File::DosGlob::glob in loop only works first time
by ikegami (Patriarch) on Feb 25, 2006 at 06:30 UTC
    The error is the "\" in front of the space in "C:/Program\ Files/". It shouldn't be there.
      Well, yes, the '\' didn't help, but leaving it blank in the Windows world wasn't helping either; the string wouldn't hang together as a single argument and so I needed to find some kind of glue to submit the file name in toto to the -f test. Perhaps it's overkill, but the current solution of using globbing with a slice does what I want. :-)
        Like I said originally, no glue necessary, just:
        # From DB $template_file = "C:/Program Files/DirDictate/soap_form/soap_final.dot +"; unless ( -f $template_file ) { ... }
        If you got that from the command line, still no glue necessary:
        # Called as: # perl script.pl "C:/Program Files/DirDictate/soap_form/soap_final.d +ot" $template_file = $ARGV[0]; unless ( -f $template_file ) { ... }