http://qs1969.pair.com?node_id=1198204

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

Getting back into perl after 15 years away and trying to learn the OO side of things.

Problem is that I'm doing something I shouldn't in the methods/subroutines, but I'm not sure what. Have looked at examples on the web that appear to do the same thing.

using activestate perl on windows

What I'm trying to achieve is to keep the dbi/sql object instantiated in the constructor by adding it to the hash that is the object (i.e. as a property) The subroutines can then grab that from the hash and use it, rather than having to re-create it.

Here's the code.

package AXSQL; # Our libraries use lib 'C:\Users\Jay\Desktop\SBS DEV\CODE\perl\Utilities'; use AXControl; use strict; use warnings; use DBI; # SQL object removes the need to handle the complexity of SQL connecti +ons and processing in individual programs package SQL; sub new # Constructor { my $class; my $sql; my @bindparms; my $Rowcount; my $Status; my $cntl; my $db; my $start; my $end; my $posn; my $SQLStr; my $host; my $Properties; @bindparms = $_; $class = shift @bindparms; $cntl = shift @bindparms; $sql = shift @bindparms; $db = $cntl->{"SysHandle"}; if (substr($sql,1,4) eq 'SQL.') { # Get SQL from the file directories $sql = $db->prepare("SELECT SQLTEXT FROM SQLDEFN WHERE SQLID = + substr($sql,5)") or die 'Couldnt run sql: '. $db->errstr; $sql->execute(); ($SQLStr) = $sql->fetchrow_array(); if ($sql->rows == 0) { return "SQL does not exist" } } #Resolve host variables $start = 1; $posn = index($SQLStr, ":"); while ($posn != -1) { $end =index(substr($SQLStr,&posn, length($SQLStr) - $posn + 1) +, " "); $host = substr($SQLStr, $posn, $end - $posn); $SQLStr =~ s/$host/@bindparms [ substr($host,2,length($host) - +1)]/g; $posn = index($SQLStr, ":"); } $sql = $db->prepare($SQLStr); $sql->execute(); $Properties= {}; bless ($Properties, $class); $Properties->{'SQL'} = $sql; $Properties->{'String'} = $SQLStr; } Sub Fetch { my $class = shift; my $sql = $class->{SQL}; #return $sql->fetchrow_array(); } Sub RowCount { $class = shift; $sql = $class->{SQL}; return $sql->rows; } 1; Here's the error messages C:\Users\Jay\Desktop\SBS DEV\CODE\perl\Utilities>perl -c AXSQL.pm Semicolon seems to be missing at AXSQL.pm line 81. Number found where operator expected at AXSQL.pm line 90, near "1" (Missing semicolon on previous line?) syntax error at AXSQL.pm line 78, near "my " Global symbol "$sql" requires explicit package name (did you forget to + declare " my $sql"?) at AXSQL.pm line 78. Global symbol "$class" requires explicit package name (did you forget +to declare "my $class"?) at AXSQL.pm line 78. Global symbol "$class" requires explicit package name (did you forget +to declare "my $class"?) at AXSQL.pm line 85. Global symbol "$sql" requires explicit package name (did you forget to + declare " my $sql"?) at AXSQL.pm line 86. Global symbol "$class" requires explicit package name (did you forget +to declare "my $class"?) at AXSQL.pm line 86. Global symbol "$sql" requires explicit package name (did you forget to + declare " my $sql"?) at AXSQL.pm line 87. syntax error at AXSQL.pm line 88, near "}" AXSQL.pm had compilation errors.
Here are the error messages
C:\Users\Jay\Desktop\SBS DEV\CODE\perl\Utilities>perl -c AXSQL.pm Semicolon seems to be missing at AXSQL.pm line 81. Number found where operator expected at AXSQL.pm line 90, near "1" (Missing semicolon on previous line?) syntax error at AXSQL.pm line 78, near "my " Global symbol "$sql" requires explicit package name (did you forget to + declare " my $sql"?) at AXSQL.pm line 78. Global symbol "$class" requires explicit package name (did you forget +to declare "my $class"?) at AXSQL.pm line 78. Global symbol "$class" requires explicit package name (did you forget +to declare "my $class"?) at AXSQL.pm line 85. Global symbol "$sql" requires explicit package name (did you forget to + declare " my $sql"?) at AXSQL.pm line 86. Global symbol "$class" requires explicit package name (did you forget +to declare "my $class"?) at AXSQL.pm line 86. Global symbol "$sql" requires explicit package name (did you forget to + declare " my $sql"?) at AXSQL.pm line 87. syntax error at AXSQL.pm line 88, near "}" AXSQL.pm had compilation errors.
All insights greatly appreciated