Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need some help with Perl Error!

Status
Not open for further replies.

Talksiggz

Technical User
May 2, 2012
3
0
0
US
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\ 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\ line 56, at end of line
syntax error at C:\inetpub\ 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.
 
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__
 
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.
 
> 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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top