in reply to how to copy files with spaces in name

problem is that file names with spaces cause this line to fail

Show your failing code. I suspect your directory reading code to cause the problem. Did you check that $groupFile actually holds the file name with embedded spaces? This works for me:

use File::Copy; use Cwd; my $file = 'foo bar'; my $dest = 'dest dir'; my $cwd = getcwd(); my $src = "$cwd/$file"; open my $fh, '>', $file or die "Can't write '$file': $!\n"; close $fh; mkdir $dest or die "Can't mkdir '$dest': $!\n"; copy ($src, $dest) or die "Can't copy '$src' to '$dest': $!\n";

Also, don't interpolate single variables. Don't say copy ("$groupFile","$errDir"), say copy ($groupFile, $errDir)

Replies are listed 'Best First'.
Re^2: how to copy files with spaces in name
by ric.techow (Initiate) on Mar 06, 2009 at 12:41 UTC
    You were right on the money. I wasn't getting the value in $grpfile I was expecting and I was jumping to conclusions. Thanks. I must say I'm impressed by you monks. The helpfulness and consideration given to beginers like me is fantastic. Thanks again everymonk. My beginning Perl book also says not to interpolate single variables and that other programmers will laugh at you behind your back (direct quote) :). I see that it is unnecessary now but are there any more sinister consequences?

      Thanks for the kudos ;-)
      Interpolation stringifies. Sinister consequences come to bite you if you get the habit and do so with references:

      use strict; my $arrayref = [ qw(a b c) ]; my %hash; $hash{abc} = $arrayref; # ok print $hash{abc}->[2],"\n"; # prints c $hash{abc} = "$arrayref"; # oops, reference converted to a string print $hash{abc}->[2], "\n"; # barfs __END__ c Can't use string ("ARRAY(0x9f43c28)") as an ARRAY ref while "strict re +fs" in use at - line 5.