On 12/30/05, David Gilden <[EMAIL PROTECTED]> wrote:
> In the Script below the line: last if ($num >= 35)
> is giving me this error: Use of uninitialized value in int
That's not an error, but a warning. You will find that execution goes
after this.
> How do I avoid this error?
@files probably contain a name which does not match /(\d+)/. In this
case, $1 turns to be undef, and so happens with $num (because
int(undef) -> undef) up to the numeric comparison which (under -w)
emits the warning.
To avoid the warning, maybe you don't need to process such filenames
...
$_ =~ /(\d+)/;
next unless $1; # skip to the next item
$num = int($1);
...
or you consider $num as 0 in this case, by replacing C<$num = int($1)>
with C<$num = int($1 || 0)
>
>
> my @files contains: Gambia001.tiff through Gambia100.tiff
>
> #!/usr/bin/perl -w
>
> my @files =<*>;
> $tmp= 1;
>
>
> for (@files){
> my $old = $_;
> $_ =~ /(\d+)/;
> $num = int($1);
> #$_ =~s/Gambia_Pa_Bobo_kuliyo_\d+/Gambia_Pa_Bobo_kuliyo_$tmp/i;
> print "$num\n";
> #$tmp++;
> last if ($num >= 35);
> # rename($old,$_);
> }
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>