Use of uninitialized value in concatenation

Use of uninitialized value in concatenation

am 14.11.2007 22:25:16 von 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, 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.

Re: Use of uninitialized value in concatenation

am 14.11.2007 22:49:21 von krahnj

gil wrote:
>
> 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, 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
--
use Perl;
program
fulfillment

Re: Use of uninitialized value in concatenation

am 14.11.2007 22:50:16 von smallpond

On Nov 14, 4:25 pm, gil wrote:
> 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, 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

Re: Use of uninitialized value in concatenation

am 14.11.2007 23:17:08 von Gunnar Hjalmarsson

gil wrote:
> 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??

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Re: Use of uninitialized value in concatenation

am 14.11.2007 23:42:31 von Peter Wyzl

"gil" wrote in message
news:1195075516.925803.65240@k79g2000hse.googlegroups.com...
> 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, 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

Re: Use of uninitialized value in concatenation

am 14.11.2007 23:58:37 von krahnj

smallpond wrote:
>
> On Nov 14, 4:25 pm, gil wrote:
> > 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, 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
--
use Perl;
program
fulfillment

Re: Use of uninitialized value in concatenation

am 15.11.2007 00:00:29 von krahnj

Peter Wyzl wrote:
>
> "gil" wrote in message
> news:1195075516.925803.65240@k79g2000hse.googlegroups.com...
> > 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, 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
--
use Perl;
program
fulfillment

Re: Use of uninitialized value in concatenation

am 15.11.2007 01:32:21 von Ben Morrow

Quoth 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, 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

Re: Use of uninitialized value in concatenation

am 15.11.2007 08:24:37 von krahnj

Ben Morrow wrote:
>
> Quoth 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, 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
--
use Perl;
program
fulfillment