Perhaps my wording has been too vague. The "Llama book" (in Section 15.3) provides an example to demonstrate usage of File::Basename:
#!/usr/bin/perl -w
use strict;
use File::Basename;
print "Please enter a filename: ";
chomp(my $old_name = <STDIN>);
my $dirname = dirname $old_name;
my $basename = basename $old_name;
$basename =~ s/^/not/;
my $new_name = "$dirname/$basename";
rename ($old_name, $new_name)
or warn "Can't rename '$old_name' to '$new_name': $!";
Then a 2nd example, to show additional functionality provided by File::Spec:#!/usr/bin/perl -w
use strict;
use File::Basename;
use File::Spec;
print "Please enter a filename: ";
chomp(my $old_name = <STDIN>);
my $dirname = dirname $old_name;
my $basename = basename $old_name;
$basename =~ s/^/not/;
my $new_name = File::Spec->catfile($dirname, $basename);
rename ($old_name, $new_name)
or warn "Can't rename '$old_name' to '$new_name': $!";
My question is... What additional functionality has the second script provided? Both scripts run effectively on both unix and windows systems. I'm missunderstanding the advantage that File::Spec should be adding.
Also, thanks for the tip about turning module names into clickable links! |