On 2008-11-29 16:39, Peng Yu <> wrote:
> According to http://perldoc.perl.org/File/Spec.html, no_upwards should
> remove '.' or '..'. But the following example does not do so. Can
> somebody let me know how to use no_upwards correctly?
>
> Thanks,
> Peng
>
> #!/usr/bin/perl
>
> use warnings;
> use strict;
>
> use File::Spec;
>
> my @path = ("../../../something/backup/home/../home/Desktop/");
> File::Spec->no_upwards(@path);
You are ignoring the result of File::Spec->no_upwards here.
> print "\@path = @path\n";
But anyway, looking at the source:
sub no_upwards {
my $self = shift;
return grep(!/^\.{1,2}\z/s, @_);
}
no_upwards is obviously not intended to be applied to whole paths, but
only to file names. The discription says so, but the use of the variable
name @paths in the example is confusing.
This works as expected:
#!/usr/bin/perl
use warnings;
use strict;
use File::Spec;
opendir(my $dh, '.') or die "opendir . failed: $!";
my @files = File::Spec->no_upwards(readdir($dh));
print "$_\n" for @files;
__END__
hp