ok thanks for your input. I corrected the problem in a doofangled way.. I passed type by reference to the function and only returned the hash. I don't know if I like it but it works atm.

Be careful about what you pass around, and what you return. As others already said, your parameter list gets flattened out into a list. If you return a hash, the hash gets flattened out, but if you accept the results of the call back into hash, then you are all right. NOTE: This all changes if you have a hash as one of many parameters that you are passing to a subroutine, or returning from a subroutine. If you are passing mixed parameters (scalars, lists, hashs), then your subroutine can get confused.

The safest way to pass (or return) arrays and hashes is by reference. This keeps your parameter list all scalars, since a reference is a scalar.

sub test { my $scalar1 = shift; my $array2_ref = shift; my $hash3_ref = shift; ### if you want to work with the hash, and not just ### the hash reference, then dereference the ref. my %hash3 = %$hash3_ref; print "value for hash key 'one' is $hash3{'one'}\n"; ### I prefer to just use the reference instead, and ### not create the hash by dereferencing the hash ref. print "value for hash key 'one' is $hash3_ref->{'one'}\n"; return($scalar1, $array2_ref, $hash3_ref); } my $test_scalar = "abc"; my @test_array = ( "a", "b", "c" ); my %test_hash = ( "a" => 1, "b" => 2, "c" => 3 ); ($new_scalar, $new_arrayref, $new_hashref) = test($test_scalar, \@test +_array, \%test_hash);
Sorry, now that I've preview'd my response, I can't see what your next question was.

HTH.

In reply to Re: Re: Re: Returning multiple values from a function by hmerrill
in thread Returning multiple values from a function by Grygonos

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.