File::Spec中的canonpath有什么用

File::Spec中的canonpath有什么用

File::Spec中的canonpath有什么用
$path = canonpath($path)
$path前后没什么变化。那么canonpath有什么用呢?
canonpath-- No physic.
canonpath
No physical check on the filesystem, but a logical cleanup of a path.

$cpath = File::Spec->canonpath( $path ) ;

Note that this does *not* collapse x/../y sections into y. This is by
design. If /foo on your system is a symlink to /bar/baz, then
/foo/../quux is actually /bar/quux, not /quux as a naive ../-removal
would give you. If you want to do this kind of processing, you
probably want "Cwd"'s "realpath()" function to actually traverse the
filesystem cleaning up paths like this.
[quote]#!/usr/bin/perl [quote]#!/usr/bin/perl
use File::Spec;

$path = '///home/xxx';
print $path,' ---> ',File::Spec->canonpath($path),"\n";

$path = 'home////xxxx';
print $path,' ---> ',File::Spec->canonpath($path),"\n";

$path = 'home/./././xxx';
print $path,' ---> ',File::Spec->canonpath($path),"\n";

$path = './xxx';
print $path,' ---> ',File::Spec->canonpath($path),"\n";

$path = '/..';
print $path,' ---> ',File::Spec->canonpath($path),"\n";

$path = '/../xxx';
print $path,' ---> ',File::Spec->canonpath($path),"\n";

$path = 'xxx///';
print $path,' ---> ',File::Spec->canonpath($path),"\n";[/quote]
运行这段代码,输出:[quote]///home/xxx ---> /home/xxx
home////xxxx ---> home/xxxx
home/./././xxx ---> home/xxx
./xxx ---> xxx
/.. ---> /
/../xxx ---> /xxx
xxx/// ---> xxx
[/quote]
所以,我想你应该明白 canonpath 方法的作用了吧:-)
多谢.
ofuqynf
GT3zyu <a href="http://qhjvnmpkcttn.com/">qhjvnmpkcttn</a>, [url=http://bmngxwanjbei.com/]bmngxwanjbei[/url], [link=http://qfdjuugojnlr.com/]qfdjuugojnlr[/link], http://ilmmwhtjdvjf.com/

[img]http://xthdhchifacp.com/[/img]
[COLOR=BLUE]URL:[/COLOR][url]kXrCuJlfutuAuyi[/url]