Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Syntactic Confectionery Delight
 
PerlMonks  

Re: Passing a list to an Object

by danger (Priest)
on Jan 13, 2001 at 01:54 UTC ( [id://51546]=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 Passing a list to an Object

First of all, there were a couple syntax errors in your posted code, please paste in the real code whenever possible to avoid typos.

When making an object or class method call like:

$obj->method(arg); #or Class->method(arg); # your example

The method actually receives the $obj or 'Class name' as its first argument (depending on which call you made). So in your example, in your doThat() method you are assigning the following:  %ARGS = ('chew', 'meat', 'MyObject', 'chew', 'bananas').

So, 'MyObjects' is taken as a key with a value of 'chew' and 'bananas' is left just sitting there doing nothing. If you had -w turned on you would have been warned about assigning an odd number of elements to a hash.

Replies are listed 'Best First'.
Re: Re: Passing a list to an Object
by lzcd (Pilgrim) on Jan 13, 2001 at 02:22 UTC
    Sorry about the typo's.

    Okay now that I've got this situation, what's the easiest way to get around it?

    How does one pass a list and not wind up with an odd numbered hash?

      Simply shift off the first argument from @_ before proceeding with messing with it:

      sub doThat { my $self = shift; my %ARGS = (chew => 'meat', @_); return "I like to chew $ARGS{chew}!\n"; }
        ah... delightfully simple.

        You'd be suprised at the weird and wonderful convulsions of code my brain was cooking up without the aid of that tasty tidbit.

        Much thankyou's and may you monkdom be more comfy than an old pair of jeans.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://51546]
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.