Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
When I'm passing many arguments to a sub I often bundle them up into a hash ref and pass that. Similarly, if the sub returns many arguments I pass them back in a hash ref too. One advantage of using a hash (i.e. named arguments) in such cases is that you're not relying on the position of the arguments. With many arguments that can start to get tricky. Building hashes also let me easily introduce lots of vertical white space. While some monks pour scorn on such a style I find it reads better. So there! :-)

If your dates and scores are in an AoH you can let Perl load them into a couple of tmp vars and print those rather than a long list of indexed array elements. To my eyes it looks neater and, with well chosen var names, can be self documenting.

When you're dealing with complex data structures and you're struggling to disentangle them it's worth having a look at Data::Dumper to work out what is happening.

Untested and doesn't compile.

my $args = { balance_sheets => \@balancesheets, cashflows => \@cashflows, pnl => \@pn1, # etc. # etc. }; my $F = piotroski($args); my (@dates, @scores); push @dates, $F->{date}[$_]{$co_name} for (0..4); push @scores, $F->{score}[$_]{$co_name} for (0..4); print join(qq{\t}, @dates), qq{\n}; print join(qq{\t}, @scores); sub piotroski { my $args = shift; # # do something with args # my $F = { date => $date_ref, score => $F_SCORE_ref, score_box => $F_SCORE_BOX_ref, roa => $F_ROA_ref, # etc. # etc. } return $F; }
updated: fixed key name typo

In reply to Re: Referencing/returning array of hashes from sub by wfsp
in thread Referencing/returning array of hashes from sub by PoGGiE

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 rifling through the Monastery: (2)
As of 2022-10-01 17:58 GMT
Find Nodes?
    Voting Booth?
    My preferred way to holiday/vacation is:

    Results (3 votes). Check out past polls.