odd number of elements in hash
I'm trying to debug some perl code written by someone else. It has a line:
Code:
Daemon::Generic->newdaemon( Code:
Odd number of elements in hash assignment at /usr/local/share/perl5/Daemon/Generic.pm line 22. Code:
my (%args) = @_; Code:
Daemon::Generic::newdaemon('Daemon::Generic', 'progname', 'mycach', 'configfile', '/ekb/mycach.conf', 'pidfile', '/var/run/mycach.pid') Thanks! |
Hi,
it seems that you have to use an even number of arguments to the "constructor" function. Namely pairs of key and value, look here http://perldesignpatterns.com/?NamedArguments Quote:
An explanation of the module is here at cpan http://search.cpan.org/dist/Daemon-G...E_USAGE_OUTPUT Markus |
Quote:
Code:
my %args = @_; |
Quote:
Markus |
Ah, good catch! That means there must be an error in the CPAN module. Thanks!
|
Rats, that wasn't the problem. Adding or removing parenthesis doesn't make a difference. The problem seems to be when the call is made:
Code:
Daemon::Generic->newdaemon ( Code:
('Daemon::Generic', 'progname', 'mycach', 'configfile', 'ekb/mycach.conf', 'pidfile', '/var/run/mycach.pid') Code:
('progname', 'mycach', 'configfile', 'ekb/mycach.conf', 'pidfile', '/var/run/mycach.pid') Regards, Brad |
I temporarily got around it by adding in the Daemon::Generic sub newdaemon procedure (before the my (%args) line:
Code:
if (($#_ + 1) % 2) { Regards, Brad V |
Quote:
Perl is doing "the right thing" (tm). My point is that the "->" notation prescribes this behavior - this is how Perl OO model works. The idiom is: Code:
sub foo If you do not want this behavior, you should use this: Code:
Daemon::Generic::newdaemon(...) |
Ahh, OK, thanks for the education! :) I'll make the change.
Thanks Again! |
All times are GMT -5. The time now is 01:13 AM. |