[Chicago-talk] Odd number of elements in hash assignment

Richard Reina gatorreina at gmail.com
Tue Aug 18 09:36:13 PDT 2015


With:

my $dbh = $con_object->connect($desired_db);


2015-08-18 11:25 GMT-05:00 imran javaid <imranjj at gmail.com>:

> 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
>>
>
>
> _______________________________________________
> 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/ac624f89/attachment.html>


More information about the Chicago-talk mailing list