I think this is close - I made a few changes but I am still only getting the 1st tier of keys when I really want all sublevels of keys. I would like $user_inputs to be an array ref which contains:

profiles, linewidth, single_dotnotes, legend, xvars, yvars

when I try pushing the return of the subfunction I get a bunch of wierd empty returns

function call

my $user_inputs = analyse_user_inputs($Settings); print Dumper($user_inputs);

incoming hash/array combo

$Settings = { batchplot_output_filename => "gps3", plot_all_variables => 'off', # DEFAULT PLOTS & VALUES default_values => [ { profiles => [qw(prof1 prof2)], linewidth => ["2"], single_dotnotes => 'On', legend => ["On"], }, ], #BEGIN CUSTOM PLOTS custom_plots => [ [ { yvars => 'LATDIIP', xvars => 'ELONGI', }, ], ] }

subfunction

sub analyse_user_inputs { my $hashORarray_ref = shift @_; my @the_inputs; if (ref $hashORarray_ref eq 'HASH') { foreach ( keys %{$hashORarray_ref} ){ # print "$_ \n"; push @the_inputs , $_ ; analyse_user_inputs($hashORarray_ref->{$_}); } } if (ref $hashORarray_ref eq 'ARRAY') { for (my $i = 0; $i < scalar(@{$hashORarray_ref}); $i++) { analyse_user_inputs($hashORarray_ref->[$i]); } } return(\@the_inputs); }

In reply to Re^2: subroutine memory variable scope by austinj
in thread subroutine memory variable scope by austinj

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.