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

In reply to OO method wont parse by jorba

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.