Help - Search - Member List - Calendar
Full Version: passing hash to a subroutine
WorkTheWeb Forums > Webmaster Resources > Perl Beginner Help
Support our Sponsors!
Good afternoon everyone,

I am trying to pass a hash of parameters to a subroutine and I get the
error
<error>
Odd number of elements in anonymous hash at ./test.pl line 5.
Odd number of elements in anonymous hash at ./test.pl line 5.
-title,HASH(0x8160d38),-author,HASH(0x8160eb8)
</error>

the code of the test script is:

<code>
#!/usr/bin/perl

use strict;
use warnings;

&test('-title'=>{'thetitle'}, '-author'=>{'name'});

sub test {
print join(',',@_), "n"

}
</code>

I am passing however even number of parameters! cause if I am not
mistaken => is consider as a comma.

What is the proper way to do this?

Regards,
cgavos

aqua red
No { }
&test('-title'=>'thetitle', '-author'=>'name');


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2005 Invision Power Services, Inc.