in reply to Why isn't this subroutine working?

Okay, you posted code that has an obvious syntax error (elsf) and a fairly clear case where you misuse single-quotes ('$rowName'), you ask why it doesn't work, we mention these things, and you say "no, that's not the problem."

If you are running a program that compiles, runs and does something (even something wrong -- i.e. perl doesn't report a syntax error), then the code you are running is different in at least one crucial detail from the code that you posted. So you are showing us the wrong problem.

(Update: in case you didn't figure it out from your dialog with ikegami, when your IDE reports a syntax error, it's because perl reported a syntax error; the script won't run at all until you fix the syntax error.)

As for the single-quotes around $rowName when you use that as a hash key, that's just wrong. Don't do that. You can waste a little time putting double-qoutes around the variable if you really want to do that, but it will make no difference relative to using the variable with no quotes at all.

Try putting some debugging output like this:

warn "this_var=$this_var; that_var=$that_var\n";
at strategic points, and watch what comes out on STDERR. Or step through the process with "perl -d your_script_name", and use the debugger to place breakpoints and inspect variables in this troublesome subroutine.

Apart from all that, if the "table's last row number" is really just the number of rows in the table (which is how I would normally interpret the phrase), then what's wrong with doing this:

sub lastRowNum { my ( $dbh, $table ) = @_; my ( $rowcount ) = $dbh->selectrow_array( "select count(*) from $t +able" ); return $rowcount; }
Or, if "last row number" means something else, like "highest numeric index in the table's primary key field", then you could do something this:
sub lastRowNum { my ( $dbh, $key_fld, $table ) = @_; my ( $last_id ) = $dbh->selectrow_array( "select max($key_fld) fro +m $table" ); return $last_id; }
No extra module or subroutines required. Keep it simple. (Updated to structure these last two examples as complete subroutines.)

Replies are listed 'Best First'.
Re^2: Why isn't this subroutine working?
by ikegami (Patriarch) on May 20, 2009 at 18:09 UTC

    (Update: in case you didn't figure it out from your dialog with ikegami, when your IDE reports a syntax error, it's because perl reported a syntax error; the script won't run at all until you fix the syntax error.)

    EPIC (the Eclipse module for Perl support) uses PPI to parse the program or module and identify warnings and errors before it is executed, so false positives and false negatives are possible. But it's unlikely.