in reply to Re: passing hash elements as parameters
in thread passing hash elements as parameters

Okay, I think I see what my mistake was. In my original sub get_events I had the line my ($formdata, $location) = @_ in order to grab the vars being passed. I think my mistake was that the individual vars weren't being passed, but rather an array containing the references to the hash and the scalar.

Tell me if I'm right from your above code:
# get the reference to the array [args] my $ref = shift; # 1st element in array = reference to %formdata # 2nd element in array = scalar $filelocation my $hashref = $ref->[0]; my $fileloc = $ref->[1];
Am I understanding this correctly?

Replies are listed 'Best First'.
Re: Re: Re: passing hash elements as parameters
by hiseldl (Priest) on Oct 09, 2002 at 20:32 UTC

      I think my mistake was that the individual vars weren't being passed, but rather an array containing the references to the hash and the scalar.

    You're mostly correct; an array reference containing the elements are being passed, not just a plain array. Here's a breakdown that might help:

    args => [ # start an array reference \%formdata, # pass a hash reference $filelocation # pass a scalar ] # end an array reference # if you are passing this as an argument to your sub, you # need to dereference it sub mysub { $ref = shift; # now we have the array ref # use array reference notation to access the elements $first_element = $ref->[0]; }

    --
    hiseldl
    What time is it? It's Camel Time!

Re: Re: Re: passing hash elements as parameters
by robartes (Priest) on Oct 09, 2002 at 20:37 UTC
    You are right. You weren't passing an array but a reference to an array, so:
    ($formdata,$location)=@_;
    would result in $formdata containing an arrayref and $location being undefined.

    CU
    Robartes- just butting in :)