Re: Uninitialized value in pattern match



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/





Relevant Pages

  • Re: Import Members into a DL from .csv file
    ... Please do not send email directly to this alias. ... foreach loop, and invoke add-distributiongroupmember within the foreach. ... Finally this is the command i am running the below command to import this ... roperties do not match any of the parameters that take pipeline input. ...
    (microsoft.public.exchange.admin)
  • Re: Help: Process many files at the same time
    ... If you want to read all files on the command line, one after the other, ... Even with the useless foreach loop around the ... After this first iteration, @ARGV is empty, so there ...
    (comp.lang.perl.misc)
  • Re: dict critique
    ... foreach to be more list oriented in its name. ... why name the dict command that is based on it differently. ... giving benefit to me through thier time). ... the exact subcommand and its semantics too often. ...
    (comp.lang.tcl)
  • Re: How do I add a record to an MS Access database
    ... // To build this sample from the command line, ... Console.WriteLine("tables in data set", ... foreach ... > I am using VS.NET 2003 and I have made a connection to a MS Access ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Perl Script - Not Getting Results When Using Command Line Arguments
    ... @SORTED_DIRLIST = sort @DIRLIST; ... # foreach $result ... The only section that works is the first one with no command line ... you should also move the actual work your script does into subroutines. ...
    (perl.beginners)