Hash as function argument.. plz help!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Karel Kubat

    Hash as function argument.. plz help!

    Hi all,
    I have a problem with a snippet of code. I'm trying to pass a hash as an
    argument to a function. Below is some test code:

    --- snip snip
    use strict;

    my %map = {
    1 => 'one',
    2 => 'two',
    3 => 'three',
    };

    sub fun {
    my $what = shift;
    my %hash = @_;

    print ("$what: ");
    foreach my $k (keys (%hash)) {
    print (" [$k]=[$hash{$k}]");
    }
    print ("\n");
    }

    # Why won't this work..
    fun ("whatever", %map);

    # But this will ?!
    fun ("again",
    'a' => 'first char', 'b' => 'second');
    --- snip snip

    What am I doing wrong (obviously near the comment mark "why won't this
    work")? Any and all help will be appreciated!

    Thanks in advance,
    --
    Karel Kubat <karel@e-tunity.com, karel@qbat.org>
    Phone: mobile (+31) 6 2956 4861, office (+31) (0)38 46 06 125
    PGP fingerprint: D76E 86EC B457 627A 0A87 0B8D DB71 6BCD 1CF2 6CD5

    Edward Chilton: "I'm worried that the universe will soon need
    replacing. It's not holding a charge."

  • Roel van der Steen

    #2
    Re: Hash as function argument.. plz help!

    On Mon, 15 Mar 2004 at 15:13 GMT, Karel Kubat wrote:[color=blue]
    > Hi all,[/color]

    Hi Karel,

    Please try to keep cross-posting to a minimum. Also, this
    newsgroup is supposed to be defunct. So posting to clpmisc
    would have been sufficient. You may want to have a look
    at the posting guidelines for clpmisc at:


    Comment

    Working...