Use of uninitialized value in pattern match (m//)

X

Xzanron

Hi

my foray into the world of perl continues.

The warning i'm getting is: Use of uninitialized value in pattern match
(m//)

I think this might be a style issue, because my program seems to work
correctly, yet I still get this warning. I could turn warnings off, but
since i'm new to this i'd rather not. Since it's a CGI script, the
warning is causing server errors (missing headers etc).

I don't understand how this value can be uninitialised, as i'm
assigning something to it.

The question is then; what am I doing wrong and how do I get rid of
this warning?

The relevant portion of my code is:

foreach my $row ($ts->rows)
{
if (@$row[1] =~ m/Some Pattern/)
{
#do stuff
}
}

Thanks,

Martin
 
X

Xzanron

Ok.. i've figured out what it was.

one of the values I was putting into the array was being treated as
uninitialised... so I just added a check of

if (defined @$row[1])

and everything is now happy...

except i'm still getting server errors... *sigh*
 
A

Anno Siegel

Xzanron said:
Hi

my foray into the world of perl continues.

The warning i'm getting is: Use of uninitialized value in pattern match
(m//)

I think this might be a style issue, because my program seems to work
correctly, yet I still get this warning. I could turn warnings off, but
since i'm new to this i'd rather not. Since it's a CGI script, the
warning is causing server errors (missing headers etc).

I don't understand how this value can be uninitialised, as i'm
assigning something to it.

The question is then; what am I doing wrong and how do I get rid of
this warning?

The relevant portion of my code is:

foreach my $row ($ts->rows)
{
if (@$row[1] =~ m/Some Pattern/)

It would be better to write $row->[1] instead of @$row[1]. The latter is
formally an array slice (of only one element). It works in scalar context,
but only because Perl does what you mean. Wonder why it doesn't warn about
it, it usually does.
{
#do stuff
}
}

Despite the formality, the code should work as (probably) intended.
Apparently the second element *is* undefined in some of the rows.

Your turn.

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top