Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I also believe that we all can contribute to each other's growth by sharing knowlege and experiences. I would love to take my skills and help people around the world solve problems..."

Geography

Where in the world do Tek-Tips members come from?

Need some help with Perl Error!

Talksiggz (TechnicalUser)
2 May 12 16:23
Hey everyone,

I am very new to Perl and I am having an issue with the following code:

**************************************************************
package GUI::DB;

use strict;
use DBI;

use vars qw(@ISA @EXPORT);
use Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(dbConnect query);


# dbConnect - connect to the database, get the database handle

sub dbConnect {
        
        # Read database settings from config file:
        my $dsn = "dbi:mysql:test:localhost:3306";
        my $dbh = DBI->connect( $dsn,'test','test',{ RaiseError => 1 });

        return $dbh;

}


# query - execute a query with parameters
#       query($dbh, $sql, @bindValues)

sub query {
        my $dbh = shift;
        my $sql = shift;
        my @bindValues = @_;            # 0 or serveral parameters

        my @returnData = ();

        # issue query
        my $sth = $dbh->prepare($sql);

        if ( @bindValues ) {
                $sth->execute(@bindValues);
        } else {
                $sth->execute();
        }

        if ( $sql =~ m/^select/i ) {
                while ( my $row = $sth->fetchrow_hashref ) {
                        push(@returnData, $row);
                }
        }

        # finish the sql statement
        $sth->finish();

        return @returnData;
}

__END__

**************************************************************

The perl logs are displaying the following error:
*** 'C:\inetpub\wwwroot\module\db2.pm' log message at: 2012/05/02 16:05:21
Precompiler: Fatal Eval Error:
    Package:[PerlEx::Precompiler::c_::inetpub::wwwroot::module::db2_pm]
    File:[C:\inetpub\wwwroot\module\db2.pm]
    Error:[Missing right curly or square bracket at C:\inetpub\wwwroot\module\db2.pm line 56, at end of line
syntax error at C:\inetpub\wwwroot\module\db2.pm line 56, at EOF
]

I can't seem to resolve this one, I have went through each bracket in this code and there doesn't seem to be anything missing.

I will provide my system info if it helps at all:
OS: Windows 7 64 bit
Perl version: ActivePerl version 5.14.2.1402 (x86)

I have set this up with IIS 7, and it perl seems to work fine, it's just this module that is giving me problems.

Any help will be appreciated.
Talksiggz (TechnicalUser)
2 May 12 16:57
Sorry guys,

Let me re-post the code in a more readable format:

CODE

package GUI::DB;

use strict;
use DBI;

use vars qw(@ISA @EXPORT);
use Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(dbConnect query);


# dbConnect - connect to the database, get the database handle

sub dbConnect {
        
        # Read database settings from config file:
        my $dsn = "dbi:mysql:test:localhost:3306";
        my $dbh = DBI->connect( $dsn,'test','test',{ RaiseError => 1 });

        return $dbh;

}


# query - execute a query with parameters
#       query($dbh, $sql, @bindValues)

sub query {
        my $dbh = shift;
        my $sql = shift;
        my @bindValues = @_;            # 0 or serveral parameters

        my @returnData = ();

        # issue query
        my $sth = $dbh->prepare($sql);

        if ( @bindValues ) {
                $sth->execute(@bindValues);
        } else {
                $sth->execute();
        }

        if ( $sql =~ m/^select/i ) {
                while ( my $row = $sth->fetchrow_hashref ) {
                        push(@returnData, $row);
                }
        }

        # finish the sql statement
        $sth->finish();

        return @returnData;
}

__END__
audiopro (Programmer)
3 May 12 14:41
You have an error at line 56.
There are only 39 lines of code.
Is this really db2.pm?

Keith
www.studiosoft.co.uk

ProbablyDown (MIS)
3 May 12 16:00
56 lines including whitespace  
Talksiggz (TechnicalUser)
3 May 12 16:13
Hey guys,

Thanks for the reply but I managed to resolve this.

I removed '__END__' from the end of the code and it works fine. Not sure if this statement is supported on the ActivePerl version I'm using? Who knows.
rovf (Programmer)
8 May 12 9:39
> Not sure if this statement is supported on the ActivePerl

I wouldn't call __END__ a "statement", but ... yes, it is Perl standard, and works well with ActiveState Perl too.
 

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close