Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

The following is an abstraction that shows a way to do what you want. It will handle "... a lot of values ..." and can be extended (e.g. you could add support for hashrefs at some later time).

[ ~/tmp ] $ cat return_multi_refs # return_multi_refs use strict; use warnings; use constant REF_SYM_MAP => { '' => ['$', '', ''], SCALAR => ['$', '${', '}'], ARRAY => ['@', '@{', '}'], }; my $rh_params = subroutine(); spawn_vars($rh_params); { no strict qw(vars); no warnings qw(once); print "scalar1 [$scalar1]\nscalar2 [$scalar2]\nscalar3 [$scalar3]\ +n", "array1[1] [$array1[1]]\narray2[2] [$array2[2]]\n"; } exit; sub subroutine { my @array1 = ( qw(a b c ) ); my $ra_array2 = [ qw(x y z) ]; my $scalar2 = 'Scalar the Second'; my $scalar3 = 'Scalar the Third'; my %params = ( scalar1 => 'Scalar the First', array1 => \@array1, scalar2 => \$scalar2, array2 => $ra_array2, scalar3 => $scalar3, ); return \%params; } sub spawn_vars { eval join '', map {( REF_SYM_MAP->{ref($_[0]->{$_})}[0], __PACKAGE__, '::', $_, + ' = ', REF_SYM_MAP->{ref($_[0]->{$_})}[1], '$_[0]->{', $_, '}', REF_SYM_MAP->{ref($_[0]->{$_})}[2], ';', )} keys(%{$_[0]}); die $@ if $@; }

Test output:

[ ~/tmp ] $ perl return_multi_refs scalar1 [Scalar the First] scalar2 [Scalar the Second] scalar3 [Scalar the Third] array1[1] [b] array2[2] [z] [ ~/tmp ] $



In reply to Re: passing array references by Prior Nacre V
in thread passing array references by cosmicperl

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2022-07-02 14:53 GMT
Find Nodes?
    Voting Booth?
    My most frequent journeys are powered by:

    Results (103 votes). Check out past polls.