in reply to Re: Passing commands to subroutines
in thread Passing commands to subroutines

This site has a pretty good discussion of these sorts of problems, and helped me in a similar situation.

In particular this fix worked well for me and seemed fine when moving between Unix and windows (i didn't try anything else)...

"Spaces could be transparently handled (no pun intended) with U+00A0, a non-breaking space, which in fact it is. Really. If the system is presented with a filename containing U+0020, it just replaces it unilaterally with U+00A0."

Hope this helps

UPDATE:

This clearly isn't how i got round the problem too, as it doesn't get around the original problem (see example below)... Thanks JavaFan

#!/usr/bin/perl use strict; use warnings; use encoding 'utf8'; my $dir = "/tmp/Foo"; unless (-e $dir){ mkdir $dir or die; } chdir $dir or die; opendir my $dh, $dir or die; my @files = readdir $dh; closedir $dh; print "Got ", scalar @files, " files\n"; foreach my $char ("\x{20}", "\x{A0}") { my $file = "foo{$char}bar"; open my $fh, ">", $file or die; } opendir $dh, $dir or die; @files = readdir $dh; closedir $dh; print "Got ", scalar @files, " files\n"; open my $fh, ">", 'foo baz' || die "Failed to open file : $!"; close $fh || die "Failed to close file : $!"; foreach my $char ("\x{20}", "\x{A0}") { my $file = "foo".$char."baz"; if (-e $file){ print "got it\n" } else { print "not got it...\n"; } } system("cat foo\x{20}baz"); system("cat foo\x{A0}baz");

Just a something something...

Replies are listed 'Best First'.
Re^3: Passing commands to subroutines
by JavaFan (Canon) on Jul 01, 2009 at 17:11 UTC
    Replacing characters in file names is just plain wrong in Unix. A space is a space, and not something else. And something that isn't a space, just isn't.
    #!/usr/bin/perl use 5.010; use strict; use warnings; my $dir = "/tmp/Foo"; mkdir $dir or die; chdir $dir or die; opendir my $dh, $dir or die; my @files = readdir $dh; closedir $dh; say "Got ", scalar @files, " files"; foreach my $char ("\x{20}", "\x{A0}") { my $file = "foo{$char}bar"; open my $fh, ">", $file or die; } opendir $dh, $dir or die; @files = readdir $dh; closedir $dh; say "Got ", scalar @files, " files"; __END__ Got 2 files Got 4 files
    See, two different files - one with a space, the other with a non-breaking space. No automatic conversion between them.