Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I may be missing the point here...

Since you seem to be using global variables anyway, you don't need to even return anything from build_list.

You are passing in references to hashes. Those hashes are being modified by build_list. Your assignment to the hashes from the return value of build_list is redundant. They are already modified when build_list returns. Just use %RECORDxRI_count and %EACH_RECORD.

I assume you are doing more in build_list and the <DATA> loop than you actually posted...

Here is some condensed code (since you expressed interest in minimizing lines of code):

my %RECORDxRI_count; my %EACH_RECORD; sub build_list { my( $RECORD, $RI, $RECORDxRI, $RECORDxRI_count_REF, $EACH_RECORD_REF + ) = @_; $RECORDxRI_count_REF->{$RECORDxRI}++; $EACH_RECORD_REF->{$RECORD} = ''; } while <DATA> { my( $Record54, $Record38 ) = (split /\t/)[54, 38]; my $RECORD = (split /{/, $Record54)[0]; $RECORDxRI = $RECORD . ',' . $Record38; build_list( $RECORD, $RI, $RECORDxRI, \%$RECORDxRI_count, \%EACH_REC +ORD ); }
Notes:
  • I explicitly named the "global" variables, just for ease-of-maintenance.
  • $RI was always unused in build_list — I left it here because I suppose you are doing more than the posted code shows.
  • You had @ instead of $ when getting indices from @record. If you only want one value, don't use a slice.
  • I almost just defined the "global" hashes as references in the first place (to avoid the backslashes altogether).
    Update: See btrott's answer for more on this.
    Like:
    my $RECORDxRI_count = {};
    my $EACH_RECORD     = {};

Hope this is helpful...
Russ


In reply to Re: defining a HASH table by reference and using it in a sub function by Russ
in thread defining a HASH table by reference and using it in a sub function by Buckaroo Buddha

Title:
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 How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-04-19 01:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found