Re: Uninitialized value in pattern match
- From: rcoops@xxxxxxxxx (Rob Coops)
- Date: Mon, 31 Mar 2008 16:52:42 +0200
Hi Johan,
Ok so lets first of all see what is in this variable called: $PkgList
I suggest using a command like, just before the foreach loop (for testing
puropses):
use Data::Dumper;
print Dumper $PkgList;
You can remove this after a single run, this will print the contents of the
variable to STDOUT.
It will be an list of values, or data structures (since the next line does a
text match I would say values is the most likely thing to show up) some of
which might be empty or the entire list might be empty. In any case it is
good to have a look and see what data we are playing with.
Even the empty values are not a problem as long as they are values they are
fine for a patren match. It is the undef values that are causign the problem
here, there are a lot of ways to fix this, one could prevent the undef
values from showing up in the array in the first place, but that might cause
problems further along the code.
Since you already you do not know what this does, it would be wise to cause
as little problems as possible and simply prevent the match from being done
on undefined values.
To do this one can simply add the following line just above the if statment
(don't forget to close the if statents opening braces at the end of the if
statment you are putting this around:
if ( defined $PkgFile ) {
This will lead to the code looking like this:
foreach $PkgFile( @$PkgList )
{
if ( defined $PkgFile ) {
if( $PkgFile =~m/^\s*$/) ....
}
This way you are certain you will only attempt to match the value if it is
defined (a value assigned to that part of the array.
Regards,
Rob Coops
On Mon, Mar 31, 2008 at 3:17 PM, Johan <johanc@xxxxxxxxx> 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...)
--
To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx
For additional commands, e-mail: beginners-help@xxxxxxxx
http://learn.perl.org/
- References:
- Uninitialized value in pattern match
- From: Johan
- Uninitialized value in pattern match
- Prev by Date: Re: parser using perl
- Next by Date: Re: parser using perl
- Previous by thread: Uninitialized value in pattern match
- Next by thread: Re: Uninitialized value in pattern match
- Index(es):
Relevant Pages
|
|