Re: Use of uninitialized value Error



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
.



Relevant Pages

  • Re: decimal place checking using JDK1.3
    ... For inspiration: ... public static boolean is37digit ... int ix = s.indexOf; ...
    (comp.lang.java.programmer)
  • Re: Pattern and Regex
    ... Matcher m = p1.matcher; ... int start = 0; ... If i can't get it to work without using the modulus. ... just using the regular expression then i will use your code. ...
    (comp.lang.java.programmer)
  • Re: Why is java considered a language for "web" or "internet" programming?
    ... I don't remember reading exact things about Perl interpreter, ... load and parse bytecodes. ... I think, integer in Perl or Python or other scripting languages is some structure, with at the least field for type and value, and pointer to this structure you hold in 'i' variable. ... const int NNUM = 1000000; ...
    (comp.lang.java.help)
  • Curious benchmark results with Inline::C
    ... I've recently been toying around with Inline::C, benchmarking ... certain variations of C and Perl and examining the results. ... However, one function calls distance() to compute the distance, ... inline double inline_distance(int x, int y) ...
    (comp.lang.perl.misc)
  • Writing a module, Segmentation fault
    ... For the access to IGT+, I am writing a Module in Perl. ... banking::igtplus - Perl extension for blah blah blah ... int igt_ack( ... dXSARGS; ...
    (comp.lang.perl.modules)