Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^3: Undefined Value Error Message

by graff (Chancellor)
on Mar 15, 2014 at 03:15 UTC ( #1078416=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Undefined Value Error Message
in thread Undefined Value Error Message

Your code looks like spaghetti. I was actually surprised that it compiles, but I'm not surprised to see these warnings:

"my" variable $LastName masks earlier declaration in same scope at 107 +8385 line 32. Variable "$result_count" will not stay shared at 1078385 line 63. "my" variable $LastName masks earlier declaration in same scope at 107 +8385 line 78. "my" variable $pagesize masks earlier declaration in same scope at 107 +8385 line 124. Unrecognized escape \s passed through at 1078385 line 133. Variable "$pagecount" will not stay shared at 1078385 line 136. Unrecognized escape \s passed through at 1078385 line 140. Unrecognized escape \s passed through at 1078385 line 152. 1078385 syntax OK
The cases of '"my" variable masks earlier declaration' will probably mess things up.

The "unrecognized escapes" are cases where you seem to have an unnecessary backslash (or maybe you intended to put \" but didn't?)

The variables that "will not stay shared" happen because you're defining the "search" sub inside the scope of defining the "count" sub, the variables in question are declared (lexically scoped) inside "count", before sub search begins, and then they're being used inside "search".

That's a strange (and wrong) way to lay out subroutines. For example, consider what happens at start-up if the "reqpage" parameter you get is greater than 1: the "search" sub will be called without the "count" sub being called first, but the "$result_count" variable is only assigned a value (from a query) in the "search" "count" sub, which hasn't been called in this case. That would probably explain the problem you're describing.

There's also a missing double-quote at line 111 (the over-long line in the "heredoc"; this doesn't affect compiling, but it'll screw up your page display. (I noticed that because I used emacs with colorized text, and after that line, the coloring was inverted for code vs. string values).

So let me suggest:

  • FIX YOUR INDENTATION so that it is consistent with the actual structure of the code.
  • Move all of sub search { } so it's completely outside of sub count { }
  • Figure out how the "unshared" variables in "search" (which are now undeclared) are going to be assigned the values that they're supposed to have when the script runs with reqpage > 1
  • Maybe google around for "paging database query results in perl cgi" - I think it should be pretty easy to find some useful examples to work from.
When you see how other people handle paging, you'll probably want to start over on this script.

(Updated to get the sub names right in the middle paragraph, and a grammar blot in the suggestion list.)


Comment on Re^3: Undefined Value Error Message
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1078416]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2014-09-21 23:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (176 votes), past polls