Ron Smith wrote:
Using the following input on a Window$ OS:

filename.0001.ext
filename.0002.ext
filename.0003.ext
filename.0004.ext
filename.0005.ext

And, the following script:

#!/usr/bin/perl -w

use strict;


print "\nThis program will change the file name(s) for you.\n\n";

print "What's the current base name?: ";
chomp ( my $name = <STDIN> );

print "What's the current extention?: ";
chomp ( my $ext = <STDIN> );

my @old_names = ( glob "$name.*.$ext" );

print "\nThe following is your selection: ".
"$old_names[0] - (", ++$#old_names, " frames).\n\n";
^^^^^^^^^^^^^
Here is your problem. If you modify $#old_names you change the size of the array @old_names so you are adding an extra element to the end of the array with the value undef. The proper way to return the number of elements of an array is to use the array in scalar context.


print "\nThe following is your selection: ".
        "$old_names[0] - (", scalar @old_names, " frames).\n\n";

Or use concatenation which forces scalar context.

print "\nThe following is your selection: ".
        "$old_names[0] - (", . @old_names . " frames).\n\n";


print "Type in the new basename and hit \"Enter\": ";
chomp ( my $new = <STDIN> );

if ( $new eq "" ) {
        print "\nYou must enter a name!\n\n";
                die "rename did not occur: $!";
} else {
        for ( @old_names ) {
                next unless /^$name\.(\d+)\.$ext$/;
                my $pad = $1;
                rename $_, sprintf "$new.%04d.$ext", $pad;
        }
}

I get the following error:

Use of uninitialized value in pattern match (m//) at
line 26, <STDIN> line 3.

The script gives no errors with 'warnings' turned off.

Can I safely ignore this error?

It is a warning not an error and warnings can be ignored but not "safely".


John -- use Perl; program fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



Reply via email to