Re: Uninitialized value in pattern match



Johan wrote:

The last line of this code
foreach $PkgFile( @$PkgList )
{
if( $PkgFile =~m/^\s*$/)

gives this warning message
Use of uninitialized value in pattern match (m//) at packagefile.pm
line 838.

How can I solve this? (I have no idea what the code does...)

Some elements of @$PkgList are undefined. Beware that this may point to
errors in the preceding code that creates the array, but you can avoid
the warning by writing:

foreach $PkgFile (@$PkgList) {

next unless defined $PkgFile;

if ($PkgFile =~ /^\s*$/) {
:
:
}
}

If you expect to spend much time working on this program then it is also
well worth putting

use strict;

at the start, if it is not already there, and declaring all variables
with 'my'.

HTH,

Rob
.



Relevant Pages

  • Uninitialized value in pattern match
    ... foreach $PkgFile(@$PkgList) ... gives this warning message ... Use of uninitialized value in pattern match at packagefile.pm ...
    (perl.beginners)
  • Re: Uninitialized value in pattern match
    ... I suggest using a command like, just before the foreach loop (for testing ... which might be empty or the entire list might be empty. ... foreach $PkgFile(@$PkgList) ...
    (perl.beginners)