in reply to Script using File::Spec fails...

dirname() and basename() are exported by File::Basename, not File::Spec. So you need to use File::Basename

Replies are listed 'Best First'.
Re^2: Script using File::Spec fails...
by cgmd (Beadle) on May 26, 2007 at 03:17 UTC
    Yes, that change (adding "use File::Basename") corrects the error. I'm simply not fully understanding the distinction between implementing File::Basename and File::Spec, as presented by the text. Thanks!
      Yes, that change (adding "use File::Basename") corrects the error. I'm simply not fully understanding the distinction between implementing File::Basename and File::Spec, as presented by the text. Thanks!

      They're just two modules with different albeit somewhat related functionality. What do you mean with "implementing" anyway? BTW: you have a special and convenient shortcut to make the name of a module into a clickable link, if you like. Just write [mod://File::Basename] and it will render like File::Basename.

        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!