Beefy Boxes and Bandwidth Generously Provided by pair Networks kudra
Welcome to the Monastery
 
PerlMonks  

Re: Re: Passing a list to an Object

by lzcd (Pilgrim)
on Jan 13, 2001 at 08:59 UTC ( [id://51583]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


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 repson (Chaplain) on Jan 13, 2001 at 09: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;.
Re: Re: Re: Passing a list to an Object
by stephen (Priest) on Jan 14, 2001 at 00: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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://51583]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.