in reply to Win file/dir names w/spaces

G'day LloydRice,

You appear to have answers to your questions from various monks.

Seeing the amount of code you wrote for your tests, I thought I'd introduce you to the built-in module Test::More.

I don't have Perl running on an MSWin platform (so I can't duplicate your exact tests) but the following should give you an idea of how much coding this module can save you. I also think that, with the substantially reduced code, the tests themselves become far more obvious and the code is more readable and maintainable.

#!/usr/bin/env perl use strict; use warnings; use Test::More tests => 3; ok(-e '/Users/ken/tmp/Sample Music', 'Single quotes'); ok(-e "/Users/ken/tmp/Sample Music", 'Double quotes'); ok(-e "'/Users/ken/tmp/Sample Music'", 'Single quotes in double quotes +');

Output:

1..3 ok 1 - Single quotes ok 2 - Double quotes not ok 3 - Single quotes in double quotes # Failed test 'Single quotes in double quotes' # at ./pm_example.pl line 10. # Looks like you failed 1 test of 3.

-- Ken

Replies are listed 'Best First'.
Re^2: Win file/dir names w/spaces
by LloydRice (Beadle) on Mar 26, 2014 at 10:16 UTC

    Thanks to all who weighed in on this. I have learned a lot. Judging by the tone of many of the replies, some will be glad to hear that I have started using "strict" (at least some of the time).

    However, it turns out that the real problem was that I was mixing Perl functions for file operations with Win command lines executed via qx. What I had not considered (and learned) was that qx actions go through the Win command line interpreter, but the Perl functions, in particular, the -x tests, do not. The difference is, of course, that path/file names with spaces get chopped up by the CLI and thus required enclosing Dquotes, but work fine in the -x tests, in which case, the Dquotes mess things up.

    I am now using the Perl file operations in Win32::File and Win32::CopyFile and nearly everything is working. A little more clean-up and the job will be done.

    Again, thanks for all the help.

    Lloyd.