in reply to Re: Passing a list to an Object
in thread Passing a list to an Object

Thank you for your second opinion. :)

I seem to remember that hash arrays aren't known for thier default sorting abilities (eg. they may not keep their original insertion order.).
Doesn't a shift run the risk of killing an unintended list item?
(...or am I just getting lists, hashes and small terriers named 'Spanky' all turned around at this wrong hour of the day?)

Replies are listed 'Best First'.
Re: Re: Re: Passing a list to an Object
by stephen (Priest) on Jan 14, 2001 at 05:13 UTC
    When you say
    MyClass->doThat(chew=>'bananas')
    The arguments don't get passed as a hash. '=>' doesn't automatically transform things into hashes, but instead is the equivalent of a comma, with the side effect of ensuring that the word before it is interpreted as a string. So it's the equivalent of saying:
    MyClass->doThat('chew', 'bananas')
    Or even:
    MyClass::doThat('MyClass', 'chew', 'bananas')
    So it's a list, not a hash, and you don't need to worry about order getting scrambled. The list doesn't turn into a hash until you do something like:
    sub doThat { my $type = shift; my %input = @_; }
    Then, you've copied the list into an associative array. Until then, plain-vanilla list... Sorry to flog a dead horse, but I saw a misconception waiting to happen...

    stephen

Re: Re: Re: Passing a list to an Object
by repson (Chaplain) on Jan 13, 2001 at 14:11 UTC
    No, as danger says above, if a funtion/method is called as Class->method(); or $instance->method();, the first argument will always be the part before the class name or instance variable. He didn't mention the indirect syntax ie method Class ();, which acts the same way as the direct syntax, but is less clear except for $foo = new Class;.