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

imran javaid imranjj at gmail.com
Tue Aug 18 09:45:12 PDT 2015


Call it without any parameters.
For one thing, the code is not doing anything with the %args variable.
Secondly, you already passed $desired_db to the new() method to initialize
the class.

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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/chicago-talk/attachments/20150818/a95c396f/attachment-0001.html>


More information about the Chicago-talk mailing list