hmm .. how is the routine supposed to know the required order of return values???

Don't think it's possible without repeating yourself ... I think it's always "Anti-DRY"!

some ideas:

  1. passing names:

    my ($locked_status,$expire)=$ssh->get_user_info($loginid, qw(locked_status expire) );

  2. passing an anonymous hash with references

    $ssh->get_user_info( $loginid, {locked_status=>  \$locked_status, expire=> \$expire} );

  3. returning a hash-ref and slice it

    my ($locked_status,$expire)= @{ $ssh->get_user_info($loginid) }{ qw(locked_status expire) };

  4. returning a list and slice it

    my ($locked_status,$expire)= ( $ssh->get_user_info($loginid) )[$idx_locked_status,$idx_expire];

That's untested and I'm not sure if I got the slicing right, but at least the last example is still compatible with your actual practice. But better use constants for the indices..

Cheers Rolf


In reply to Re: Returning multiple values from subroutine by LanX
in thread Returning multiple values from subroutine by walkingthecow

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.