in reply to Re: Re: file::spec and catfile?
in thread file::spec and catfile?

OK, the problem is that you can't stick an array as an argument to catfile to do what you're trying to do. (Not that you can't use an array, it just won't do what you want.) Unless you've changed some of Perl's variables, the "@arr" is flattening the list of filenames into a single string, separating the file names with blanks. (Also, you don't have to quote $path, the first argument. Looks like you're used to shell scripting. You may want to look at Perl traps for the unwary.)

Here's one way to code your loop:

foreach my $filename (@arr) { $x = File::Spec->catfile($path, $filename); unlink $x; }
This is a rather verbose way, but you can see the correspondence to your code. Here's a one-line way to do it: unlink map {File::Spec->catfile($path, $_)} @arr;Warning: this will probably a touch off a round of golf ;-)

HTH