Use of uninitialized value in concatenation

G

gil

when running Perl in "-w" mode, I get the following warning line:

"Use of uninitialized value in concatenation (.) or string at ./
check_log.pl line 177, <DAT> line 261."

when line 177 is:

"if ($$ref =~ /^\[(\d+?)\/(\d+?)\/(\d+?)\s+?(\d+?):(\d+?):(\d+?)$
\]/)"

if you do know what's the problem, I'll be glad to know, if not -
please don't get occupied by this issue.
 
J

John W. Krahn

gil said:
when running Perl in "-w" mode, I get the following warning line:

"Use of uninitialized value in concatenation (.) or string at ./
check_log.pl line 177, <DAT> line 261."

when line 177 is:

"if ($$ref =~ /^\[(\d+?)\/(\d+?)\/(\d+?)\s+?(\d+?):(\d+?):(\d+?)$
\]/)"

You don't have a string with embedded variables or the concatenation
operator on that line so the warning must be generated by another line,
probably before this line. If you want more help show about 5-10 lines
before and after line 177.


John
 
S

smallpond

when running Perl in "-w" mode, I get the following warning line:

"Use of uninitialized value in concatenation (.) or string at ./
check_log.pl line 177, <DAT> line 261."

when line 177 is:

"if ($$ref =~ /^\[(\d+?)\/(\d+?)\/(\d+?)\s+?(\d+?):(\d+?):(\d+?)$
\]/)"

if you do know what's the problem, I'll be glad to know, if not -
please don't get occupied by this issue.

It wants to check for a time string of the form: "[dd/mm/yy hh:mm:ss]"
but $$ref has no value. I'm guessing DAT is an open file containing
about 260 lines of data.
--S
 
G

Gunnar Hjalmarsson

gil said:
if you do know what's the problem, I'll be glad to know, if not -
please don't get occupied by this issue.

What kind of stupid remark is that??
 
P

Peter Wyzl

gil said:
when running Perl in "-w" mode, I get the following warning line:

"Use of uninitialized value in concatenation (.) or string at ./
check_log.pl line 177, <DAT> line 261."

when line 177 is:

"if ($$ref =~ /^\[(\d+?)\/(\d+?)\/(\d+?)\s+?(\d+?):(\d+?):(\d+?)$
\]/)"

It would appear that at some point $$ref becomes a null value. In order to
avoid the warning you need to code in such a way that if you encounter $$ref
as a null, you do something other than bind it to the regex.

One simple way is

if ($$ref){
if ($$ref =~ /^\[(\d+?)\/(\d+?)\/(\d+?)\s+?(\d+?):(\d+?):(\d+?)$\]/){
#do whatever
}
}

So that effectively avoids the condition, but you also need to look at what
else is effected by that value potentially being a null, and handle those
error conditions too.

P
 
J

John W. Krahn

smallpond said:
when running Perl in "-w" mode, I get the following warning line:

"Use of uninitialized value in concatenation (.) or string at ./
check_log.pl line 177, <DAT> line 261."

when line 177 is:

"if ($$ref =~ /^\[(\d+?)\/(\d+?)\/(\d+?)\s+?(\d+?):(\d+?):(\d+?)$
\]/)"

if you do know what's the problem, I'll be glad to know, if not -
please don't get occupied by this issue.

It wants to check for a time string of the form: "[dd/mm/yy hh:mm:ss]"
but $$ref has no value.

If that were true you would get a different warning message:

$ perl -wle'my $x; $x =~ /\d/'
Use of uninitialized value in pattern match (m//) at -e line 1.


John
 
J

John W. Krahn

Peter said:
gil said:
when running Perl in "-w" mode, I get the following warning line:

"Use of uninitialized value in concatenation (.) or string at ./
check_log.pl line 177, <DAT> line 261."

when line 177 is:

"if ($$ref =~ /^\[(\d+?)\/(\d+?)\/(\d+?)\s+?(\d+?):(\d+?):(\d+?)$
\]/)"

It would appear that at some point $$ref becomes a null value.

If that were true you would get a different warning message.

$ perl -wle'my $x; $x =~ /\d/'
Use of uninitialized value in pattern match (m//) at -e line 1.


John
 
B

Ben Morrow

Quoth gil said:
when running Perl in "-w" mode, I get the following warning line:

"Use of uninitialized value in concatenation (.) or string at ./
check_log.pl line 177, <DAT> line 261."

when line 177 is:

"if ($$ref =~ /^\[(\d+?)\/(\d+?)\/(\d+?)\s+?(\d+?):(\d+?):(\d+?)$
\]/)"

Presuming this shouldn't be wrapped, the important part of this is

/$\]/

which is *not* an attempt to match a dollar followed by a square bracket
but an attempt to interpolate $\ followed by an invalid close-character-
class. Presumably $\ is undef. You need to escape the $:

/^\[...(\d+?)\$\]/

or perhaps it was meant to be the other side of the \].

In a case like this it is well worth using alternate delimiters and /x:

m{ ^
\[
(\d+?) / (\d+?) / (\d+?) \s+?
(\d+?) : (\d+?) : (\d+?) \$
\]
}x

*Much* more readable. Also, since the match is anchored and none of :, /
or \s match \d, none of those ?s are doing anything for you.

Ben
 
J

John W. Krahn

Ben said:
Quoth gil said:
when running Perl in "-w" mode, I get the following warning line:

"Use of uninitialized value in concatenation (.) or string at ./
check_log.pl line 177, <DAT> line 261."

when line 177 is:

"if ($$ref =~ /^\[(\d+?)\/(\d+?)\/(\d+?)\s+?(\d+?):(\d+?):(\d+?)$
\]/)"

Presuming this shouldn't be wrapped, the important part of this is

/$\]/

which is *not* an attempt to match a dollar followed by a square bracket
but an attempt to interpolate $\ followed by an invalid close-character-
class.

You got the first part right but because there is no
open-character-class the ']' is just a normal character.



John
 

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

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top