Re: Use of uninitialized value Error
- From: krahnj@xxxxxxxxx (John W. Krahn)
- Date: Fri, 30 Dec 2005 13:03:38 -0800
David Gilden wrote:
> Hello,
Hello,
> In the Script below the line: last if ($num >= 35)
> is giving me this error: Use of uninitialized value in int
>
> How do I avoid this error?
You are using the results of a regular expression match without verifying that
the regular expression matched successfully. Don't do that.
> my @files contains: Gambia001.tiff through Gambia100.tiff
>
> #!/usr/bin/perl -w
>
> my @files =<*>;
> $tmp= 1;
>
>
> for (@files){
> my $old = $_;
> $_ =~ /(\d+)/;
> $num = int($1);
if ( /(\d+)/ ) {
$num = int $1;
}
Or perhaps:
next unless /(\d+)/;
$num = int $1;
Or maybe only work on files that actually have digits in them:
my @files = <*[0-9]*>;
> #$_ =~s/Gambia_Pa_Bobo_kuliyo_\d+/Gambia_Pa_Bobo_kuliyo_$tmp/i;
> print "$num\n";
> #$tmp++;
> last if ($num >= 35);
> # rename($old,$_);
> }
John
--
use Perl;
program
fulfillment
.
- References:
- Use of uninitialized value Error
- From: David Gilden
- Use of uninitialized value Error
- Prev by Date: Re: please help find logic error in home-brewed brute force anagram solver/creator script
- Next by Date: Re: please help find logic error in home-brewed brute force anagram solver/creator script
- Previous by thread: Re: Use of uninitialized value Error
- Next by thread: Re: Use of uninitialized value Error
- Index(es):
Relevant Pages
|