in reply to rename file extension

You have forgotten your sigil on old_filename. I think the line should probably read

my ($old_filename, undef, $ext) = fileparse($file,qr{\..*});

I presume that would be line 23? Note that this would have been caught by strict and the resulting errors would have made the omission quite obvious.

Replies are listed 'Best First'.
Re^2: rename file extension
by muizelaar (Sexton) on Feb 25, 2010 at 11:17 UTC
    Hi thanks for that but I now seem to seeing this other problem again something I have seen before but I guess this is what happens when you have spent almost a year not doing anything with Perl. Help much needed :-) I now see the following error Undefined subroutine &main::fileparse called at testedi line 17 (#1) (F) The subroutine indicated hasn't been defined, or if it was, it has since been undefined. Uncaught exception from user code: Undefined subroutine &main::fileparse called at testedi line 17. I have checked and double checked for mistakes like the one you pointed out, I’m sure it’s going to be something really silly again. Help much needed :-)
    #!/usr/bin/perl -w use diagnostics; use Cwd; my $dir = getcwd; my $edihome = "/home/dsadmin/EDI"; opendir(FH, $edihome); @orderlist = grep { !/^\.\.?\z/ && -e "$edihome/$_" } readdir FH; @orderlist = glob "*.tst"; my %ext_map = ( '.tst' => '.test' ); open(FHA, ">renamebatch"); for my $file (@orderlist) { my ($old_filename, undef, $ext) = fileparse($file,qr{\..*}); my $new_ext = $ext_map{$ext} || $ext; my $new_filename = $old_filename; print(FHA "$file\n"); }
      Add this:
      use File::Basename;
      And, in the future, wrap your warning/error messages in code tags as well.
        Excellent thanks for this.