Re: Use of uninitialized value Error



On 12/30/05, David Gilden <dowda@xxxxxxxxxxxxxxxxxx> 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,$_);
> }
.



Relevant Pages

  • Re: dereferencing type-punned pointer will break strict-aliasing rules
    ... our warning flags are missing other new gcc warnings. ... object code size (the memcpy gets optimized away in almost the same way ... The temporary variable with a basic type is to avoid gcc getting confused ... There is no problem loading the source operand since only its address ...
    (freebsd-current)
  • Re: give me some tips
    ... Rod Pemberton schrieb: ... avoid the use casts, except to ensure the type and precision of numerical ... If you decide that the warning is not critical and your compiler ... offers a #pragma to switch off a warning for a code section, ...
    (comp.lang.c)
  • [PATCH] Fix FRV irqs_disabled() to return an int, not an unsigned long
    ... Fix FRV irqs_disabledto return an int, not an unsigned long to avoid this ...
    (Linux-Kernel)
  • Re: need some help with threading module...
    ... But how will i learn using threads if i avoid using them ... That is an excellent reason to mess with them, it was just a warning ... controller class, please look again at what I gave you this as an ... You also mention the MVC pattern. ...
    (comp.lang.python)
  • Re: Confirm each email when running mail merge
    ... The warning comes up (for security purposes) when "another program" is ... To avoid having to click Yes on each occasion, ... services on a paid consulting basis. ...
    (microsoft.public.word.mailmerge.fields)