http://www.perlmonks.org?node_id=1078416


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:

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.)