Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to use File::Spec->no_upwards?

Reply
Thread Tools

How to use File::Spec->no_upwards?

 
 
Peng Yu
Guest
Posts: n/a
 
      11-29-2008
Hi,

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);
print "\@path = @path\n";
 
Reply With Quote
 
 
 
 
Peng Yu
Guest
Posts: n/a
 
      11-29-2008
On Nov 29, 10:39 am, Peng Yu <(E-Mail Removed)> wrote:
> Hi,
>
> According tohttp://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?


Hi,

I just find that I can use Cwd to remove '..'.

Thanks,
Peng

#!/usr/bin/perl

use warnings;
use strict;

use Cwd;

my $path = '../../../something/backup/home/../home/Desktop/';
$path = Cwd::abs_path($path);
print "\$path = $path\n";
 
Reply With Quote
 
 
 
 
Peter J. Holzer
Guest
Posts: n/a
 
      11-29-2008
On 2008-11-29 16:39, Peng Yu <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Could not use ''; file already in use. M K ASP .Net 11 04-09-2008 11:35 AM
where to use CPLD & where to use FPGA? kulkarku@math.net VHDL 6 03-06-2006 07:27 AM
Can I use XPath or something to a remote Mac or Linux box and just query an xml file, not using web services and use encyrption? jake ASP .Net 0 07-06-2004 02:16 PM
Cannot use the profile "default" because it is in use, not. please.post@yur.re.ply Firefox 1 07-04-2004 03:41 AM



Advertisments