Brent Clark am Dienstag, 13. Dezember 2005 13.25:
> Hi all

Hi Brent

> For some reason I keep geting this message.
>
> Global symbol "$arguments" requires explicit package name at sql_handler.pm
> line 37. Global symbol "$arguments" requires explicit package name at
> sql_handler.pm line 40. Global symbol "$table" requires explicit package
> name at sql_handler.pm line 48.
>
>
> Ig someone would so kind as to point out to me, where im going wrong and to
> maybe share some tips, I would be most grateful.
>
> Kind Regards
> Brent Clark
>
>
> #--------------------------------- Code below --------------------
>
> package sql_handler;
>
> BEGIN {
>     use Exporter;
>     use vars qw( $VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
>     $VERSION       = 0.1;
>     @ISA           = qw(Exporter);
>     @EXPORT        = qw(
>                       &sql_insert
>                    );
>
>     %EXPORT_TAGS   = ();
>     @EXPORT_OK     = qw();
> }
>
> use Carp 'croak';
> use strict;
> use warnings;
> use DBI;
>
>     # Lets connect to the database
>     my $database = "world";
>     my $data_source = "DBI:mysql:database=$database;host=localhost";
>     my $username = "nicetry";
>     my $auth = "nicetryagain";
>     my $dbh = DBI->connect($data_source, $username, $auth, {'RaiseError' =>
> 1} );
>
>
>     sub sql_insert {
>
>        my %arguments = @_;

This is a hash...

> #     use Data::Dumper;
> #     print Dumper(\%arguments);
>
>        my @columns = keys %{ $arguments->{'fields'}};
>        my @vals = ();
>        foreach (@columns) {
>           my $val = $arguments->{$_};

...but you use an inexistent hashref $arguments here.

>           $val =~ s/\'/\'\'/g;
>           $val =~ s/\n/\\n/g;
>           push @vals, "'".$val."'";
>        }
>
>        my @values = @_;
>        my $insert_query = "INSERT INTO $table (".join(',',@columns).")

and $table is used without being defined.

strict and warnings are great :-)

> VALUES(".join(',',@vals).")"; my $sth = $dbh->prepare($insert_query);
>        $sth->execute();
>        $sth->finish();
>
>     }
>
>     # Disconnect from the database.
>     $dbh->disconnect();
> 1;

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to