hesco has asked for the wisdom of the Perl Monks concerning the following question:

I'm confused by this error message, because the values on that line are both defined and I don't see where I am concatenating anything for it to complain about. This functions is supposed to parse an email message and pull out about six or eight fields from the mix to insert into a database.

sub parse_message { my $self = shift; my $source_email = shift; my $found_address = 0; my $address_line_count = 0; my($name_raw,$city_state_zip); my($date,$email,$name,$address1,$address2,$city,$state,$zip); my @lines = split($/,$$source_email); LINE: foreach my $line (@lines){ my $regex = '^Date:'; print STDERR $regex, "\n"; print STDERR $line,"\n"; if($line =~ m/$regex/){ # <--- line 98 $date = $line; $date =~ s/^Date: //; next LINE; } elsif($line =~ m/^From: /){ # . . . etc. } } return; }
Is giving me output like:

^Date: by my-mx.my-host.com (Postfix) with ESMTP id 93B8DD1D6E Use of uninitialized value in concatenation (.) or string at lib/path/ +to/mymodule.pm line 98.
Only repeated a dozen or more times for my test email I'm trying to parse.

Any and all ideas are appreciated.

-- Hugh

if( $lal && $lol ) { $life++; }
  • Comment on "uninitialized value in concatenation" is initialized and involves no concatenation that I can see.
  • Select or Download Code

Replies are listed 'Best First'.
Re: "uninitialized value in concatenation" is initialized and involves no concatenation that I can see.
by kyle (Abbot) on Jun 26, 2008 at 21:08 UTC

    Your undefined value is probably later on in the elsif chain. This is a common problem.

    my $def1 = 'true'; my $def2 = 'foo'; my $def3 = 'blue'; my $undef1; if ( $def1 =~ /X/ ) { # <-- problem reported here print 'not here'; } elsif ( $def2 =~ /Y/ ) { print 'not here either'; } elsif ( $undef1 =~ /$def3/ ) { # <-- problem exists here print 'oh noes'; } else { print "happiness ensues\n"; }
Re: "uninitialized value in concatenation" is initialized and involves no concatenation that I can see.
by moritz (Cardinal) on Jun 26, 2008 at 21:38 UTC
    BTW one of the nice improvements of perl 5.10 is that it tells you which variable is actually undefined. One more reason for upgrading ;-)
Re: "uninitialized value in concatenation" is initialized and involves no concatenation that I can see.
by ganeshk (Monk) on Jun 26, 2008 at 21:38 UTC

    I suppose it is in this line

    print STDERR $line,"\n";
    Even I have come across cases where perl slightly miscalculates the line numbers when reporting them in errors or warnings. My guess is because that's the print statement that has a concatenation. So please try to print the Dumper of @lines array and see where the undef comes in that array. Also probably seeing what $/ variable has can help diagnose further. Please also check the documentation for the split method for knowing when it can return an undef in the resulting list.


    Thanks,
    Ganesh
Re: "uninitialized value in concatenation" is initialized and involves no concatenation that I can see.
by Anonymous Monk on Jun 27, 2008 at 05:02 UTC
    It is almost certainly the 'or string' part of the 'Use of uninitialized value in concatenation (.) or string' message that is pertinent here.