| Adriano Ferreira 2006-01-10, 4:02 am |
| On 12/30/05, David Gilden <dowda@coraconnection.com> wrote:
> In the Script below the line: last if ($num >=3D 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
...
$_ =3D~ /(\d+)/;
next unless $1; # skip to the next item
$num =3D int($1);
...
or you consider $num as 0 in this case, by replacing C<$num =3D int($1)>
with C<$num =3D int($1 || 0)
>
>
> my @files contains: Gambia001.tiff through Gambia100.tiff
>
> #!/usr/bin/perl -w
>
> my @files =3D<*>;
> $tmp=3D 1;
>
>
> for (@files){
> my $old =3D $_;
> $_ =3D~ /(\d+)/;
> $num =3D int($1);
> #$_ =3D~s/Gambia_Pa_Bobo_kuliyo_\d+/Gambia_Pa_Bobo_kuliyo_$tmp/i;
> print "$num\n";
> #$tmp++;
> last if ($num >=3D 35);
> # rename($old,$_);
> }
|