[Chicago-talk] Odd number of elements in hash assignment
imran javaid
imranjj at gmail.com
Tue Aug 18 09:25:57 PDT 2015
Your example shows how you created the $con_object but how are you calling
the connect method after that?
On Tue, Aug 18, 2015 at 10:28 AM, Richard Reina <gatorreina at gmail.com>
wrote:
> When I use the code below I get:
>
> Odd number of elements in hash assignment at Conxtn.pm line 29.
> I have read about this in perlmonks but still don't get why it's happening
> here because as
> far as I know I am not innitializing my hash with undef. Can anyone tell
> me how I can correct so that I do not get this warning?
>
> Thanks
>
>
> use Conxtn;
>
> my $desired_db = 'user_opps';
> my $con_object = Conxtn->new(db => $desired_db);
>
>
>
>
>
>
>
> package Conxtn;
>
> use DBI;
> use strict;
> use warnings;
>
>
> #############################
> sub new {
> #############################
>
> my ( $class, %args ) = @_;
>
> bless {
>
> _db_name => $args{'db'},
> _server => $args{'server'},
>
> }, $class;
>
> #######################
> } # end of sub new
> ######################
>
> ########################
> sub connect {
> ########################
>
> my ( $self, %args ) = @_;
> my $server; # db server
>
> open MICLAVE, "/home/richard/Dancer2/MyApp/pass" or die "$!";
> chomp (my ($user, $clave) = <MICLAVE>);
> close MICLAVE;
>
> # select a server for a connection
> unless ( defined($self->{_server}) ) {
> $server = '127.0.0.1'; ### enter server IP HERE
> }
>
> my $dbh =
> DBI->connect("DBI:mysql:database=$self->{_db_name};$server",$user,$clave);
>
> return $dbh;
>
> ################################
> } # end of sub connect
> ###############################
>
> 1;
>
>
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/chicago-talk/attachments/20150818/cb2f5b36/attachment.html>
More information about the Chicago-talk
mailing list