Re: Use of uninitialized value Error



On 12/30/05, David Gilden <dowda@xxxxxxxxxxxxxxxxxx> wrote:

> $_ =~ /(\d+)/;
> $num = int($1);

If there's no digit in $_, then $1 will be undef (or worse; see
below). I think that's probably your bug: Some filename isn't like the
others. Instead of this:

> my @files =<*>;

Consider something like this:

my @files = <Gambia*.tiff>;

Later, when you're trying to get the number from the string, you can
allow for the possibility that there isn't one by checking the value
of the pattern match. If it's false, the pattern didn't match, and you
shouldn't use $1.

if (/(\d+)/) {
$num = $1;
} else {
warn "No digits found in '$_', continuing...\n";
next;
}

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training
.



Relevant Pages

  • Re: code within libraries vs code within same project
    ... Is this a bug in System.Diagnostics.StackTrace? ... //the .dll do not appear to have all the info, particularly filename. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Common dialog control returns wrong filename
    ... It is caused by the listview generating a CDN_SELCHANGE: message when the listview area is clicked. ... This is not a bug per: se, but rather the way a listview works. ... : Remember too that Word and Excel do not use the Windows common dialogs, so: their custom implementation to duplicate the functionality of the real: common dialogs may circumvent the problem. ... sometimes:: returns a different filename from the name that is displayed on the ...
    (microsoft.public.vb.bugs)
  • Re: Statistics for RCM
    ... Use of uninitialized value in pattern match at ./newsstats line 499. ... manually removed messages. ... something to get that to actually report for the whole ... a bug as a customization needed for certain groups. ...
    (rec.crafts.metalworking)
  • Re: Statistics for RCM
    ... Use of uninitialized value in pattern match at ./newsstats line 499. ... something to get that to actually report for the whole ... a problem with not enough headers. ... a bug as a customization needed for certain groups. ...
    (rec.crafts.metalworking)
  • Re: Common dialog control returns wrong filename
    ... "Franz Strele" wrote: ... >> common dialog control returns to your program a filename of an existing file ... >> instead of the new name that you put on the filename line. ... "answer" because the bug still remains, ...
    (microsoft.public.vb.bugs)