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

Richard Reina gatorreina at gmail.com
Wed Aug 19 08:01:25 PDT 2015


Thank you Chris and Imran for pointing out my redundancy.  Calling it
without the parameter fixed the problem.

Thanks again.

2015-08-18 11:45 GMT-05:00 Chris Hamilton <cjhamil at gmail.com>:

> > $con_object->connect($desired_db);
>
> You're passing a single scalar but your connect() method is looking for a
> hash (i.e. an even-number of elements).
>
> > my ( $self, %args ) = @_;
>
> Furthermore, you don't even seem to be using any of these %args in the
> connect method anyway.  Why are you passing the $desired_db string to the
> connect method (the object already knows this value)?
>
> -Chris
>
>
> On Tue, Aug 18, 2015 at 11:36 AM, Richard Reina <gatorreina at gmail.com>
> wrote:
>
>> 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
>>>
>>
>>
>> _______________________________________________
>> 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/20150819/a2af6a21/attachment.html>


More information about the Chicago-talk mailing list