The File::Spec module is used for manipulating file specifications, which are the names
of files, directories, and the other things that are stored on filesystems. Like File::Base
name, it understands what kind of system it’s running on, and it chooses the right set
of rules every time. But unlike File::Basename, File::Spec is an object-oriented (often
abbreviated OO) module.
- use File::Spec;
-
use File::Basename;
-
-
chomp(my $filename = <STDIN>);
-
$basename = basename $filename;
-
$dirname = dirname $filename;
-
-
($newbase = $basename) =~ s/^/test/;
-
-
$newfilename = File::Spec->catfile($dirname, $newbase);
-
print $newfilename, "\n";
if input is "/home/user/test.txt", the output is "/home/user/testtest.txt".
a lot of methods are list in this model.