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

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!

Replies are listed 'Best First'.
Re^3: Script using File::Spec fails...
by blazar (Canon) on May 26, 2007 at 12:35 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!

    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!
        What additional functionality has the second script provided?

        With the second script you don't have to know what the path separator is. That is, the main thing that File::Spec provides is portability. You can use File::Spec->catfile(); and it will work on whatever platform the script is run on.

        A more useful example for comparison between unix and windows would be the return value of File::Spec->devnull().

        Check out the File::Spec documentation (for which you provided a link :-) for more details.

        Cheers,
        Rob
        Both scripts run effectively on both unix and windows systems.

        Others answered your question, but the answer is also in your own words, the point being that *NIX and Windows do not exhaust the whole world. Granted: forward slashes work mostly everywhere, but if you're really concerned about portability, go the File::Spec (or File::Spec::Functions) route.