Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2024-04-20 03:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found