cletus550 has asked for the wisdom of the Perl Monks concerning the following question:

Stuck with this all day. Trying to use
HoneyClient::Agent::Driver::ActiveContent::Flash but the documentation is too terse – for me anyway.
The basic problem is that I need to pass a hash containing the arguments into extract() in the module.
I can build the hash and pass it around in the main perl script but when I call the module with the hash as a parameter it says:
Odd number of elements in the hash assignment… Cant call method “filename” on an undefined value…
Ie the hash is not being passed to the subroutine in the module.
I have been trying
%swf = ('file' => new Fl ('Myflash.swf'), 'url' => $url); %hash = HoneyClient::Agent::Driver::ActiveContent::Flash->extract(%swf +);
The module contains a subroutine:
sub extract { # Extract arguments. my %args = @_; my $filename = $args{'file'}->filename;
Suggestions for how I could send the parameter in the right way would be gratefully received.

Replies are listed 'Best First'.
Re: Pass hash to module
by toolic (Bishop) on May 29, 2010 at 23:34 UTC
    %swf = ('file' => new Fl ('Myflash.swf'), 'url' => $url);
    Use Data::Dumper to inspect the contents of the %swf hash. My guess is that it contains an odd number of elements, just like the warning message states. diagnostics can give you a little more detailed explanation of the message. Perhaps the new call returns something unexpected.

    Are you sure HoneyClient::Agent::Driver::ActiveContent::Flash even works? The CPAN Testers report no passing tests.

        The error message, oddly enough, also gives a decent explanation :)
Re: Pass hash to module
by biohisham (Priest) on May 30, 2010 at 04:41 UTC
    According to code stability status checks, this particular module needs more work, the doc is extremely concise and reflects nothing, ..

    Not really sure if '%swf = ('file' => new Fl ('Myflash.swf'), 'url' => $url);' is syntactically correct, because when white spaces are there in a hash key value that is when commas are required to enclose these values within a single unit...

    Consider Data::Dumper to view your hash and make sure it looks like what you expect....


    Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.
Re: Pass hash to module
by Anonymous Monk on May 30, 2010 at 02:38 UTC
    You're assuming new Fl ('Myflash.swf') does not fail, and that it returns something in list context. It does fail, and it returns nothing.
    $ cat junk.pl #!/usr/bin/perl -- use strict; use warnings; sub Fl::new { return } my $url ; my %swf = ('file' => new Fl ('Myflash.swf'), 'url' => $url); use Data::Dumper; print Dumper( \%swf ); __END__ $ perl junk.pl Odd number of elements in hash assignment at junk.pl line 9. Use of uninitialized value $url in list assignment at junk.pl line 9. $VAR1 = { '' => undef, 'file' => 'url' }; $ $ cat junk2.pl #!/usr/bin/perl -- use strict; use warnings; sub Fl::new { return } my $url ; my %swf = ('file' => scalar new Fl ('Myflash.swf'), 'url' => $url); use Data::Dumper; print Dumper( \%swf ); __END__ $ perl junk2.pl $VAR1 = { 'url' => undef, 'file' => undef };
Re: Pass hash to module
by Anonymous Monk on May 30, 2010 at 22:58 UTC
    You're using calling a class's method: Module->method(%foo), which passes arguments ('Module', %foo), which is an odd number of elements. The sub does not expect any arguments other than an even number of arguments which it immediately assigns to a hash (the module's documentation does not match its code). Call it as a subroutine instead: Module::method(%foo), and perhaps file a bug report and/or be ready to modify your code if, when the module is fixed, the calling conventions rather than just the documentation are changed.