mnlight wrote:

Can anyone explain why I am recieving this error.
Use of uninitialized value in concatenation (.) or string at Signup.pl line 46...

The short answer is "yes, I can explain why." You have an unitialized value in a concatenation or string. The longer answer is, "no, I don't know why you have an unitialized value." I don't know what your line numbers are, so I can't tell where the value is. Further, while I could try to figure out the offsets from your error messages and correlate those to print statements in your code, I'm not going to do that.

If you have a halfway decent editor (no, I'm not talking about Notepad), you should be able to see your line numbers. Since you're not using HERE docs (which can obscure the problem), you should be able to point almost perfectly to the line where you have an unitialized value. For example:

$ perl -e ' use strict; use warnings; my $x; print $x;' Use of uninitialized value in print at -e line 5.

I can see at a glance that the lone print statement is line 5 and, if I had a problem, I could tell the monks "Look, there's where I get the error".

So, try reporting where the error is and we'll try to narrow it down for you (though I suspect that it lies in your SQL returning nothing).

Update: I tried refactoring and cleaning up your code a little bit:

$user = $dbh->quote( $user ); my ( $field, $sub_parent ) = $parent eq 'Father' ? ( 'Father', "'Mother'" ) : ( 'Mother', "'Father'" ); $sth = $dbh->prepare ("select $field from Roster where User = $user"); $sth->execute (); my $name = $sth->fetchrow_array; if ($name eq ""){ $sth = $dbh->prepare ("select $sub_parent from Roster where User = + $user"); $sth->execute (); $name = $sth->fetchrow_array; } #end chk for not parent if statement. print $query->h1({-align=>'center'},"THANK YOU FOR SIGNING UP $name"); $sth = $dbh->prepare ("select distinct Volunteer from Volunteer where +Volunteer = ? and Date = ?"); foreach my $date ( @volunteer_date ) { $sth->execute ( $name, $date ); my $chk = $sth->fetchrow_array; if ($chk eq $name) { print $query->h1({-align=>'center'}, "You are already signed u +p for this date: $date"); } #end if statement else { $sth = $dbh->prepare ("select max(Number) from Volunteer where + Date = ? and Volunteer = 'TBD'"); $sth->execute ($date );

After doing this, I saw that you are not using strict and you have some serious scoping issues. These scoping issues make this difficult. As I see from your code below, the problem lies in $user not being initialized.

$sth = $dbh->prepare ("select Mother from Roster where User = \'$user\ +'");

Thus, your problem occurred before the snipped that you presented us with. Also, note in my cleanup above that I used the $dbh->quote method. This will save you much grief, rather than trying to escape the data with single quotes (if the data contains single quotes, your escaping it will fail, for example). I suggest you read the DBI documentation very carefully.

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.


In reply to (Ovid) Re: uninitialized value in concatenation by Ovid
in thread uninitialized value in concatenation by mnlight

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.