Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

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

How do I do this in one line?

sub build_list { ($RECORD,$RI,$RECORDxRI,$RECORDxRI_count_REF,$EACH_RECORD_REF) = @ +_; %RECORDxRI_count = %$RECORDxRI_count_REF; %EACH_RECORD = %$EACH_RECORD_REF; $RECORDxRI_count{$RECORDxRI}++; $EACH_RECORD{$RECORD} = ''; return(\%RECORDxRI_count,\%EACH_RECORD); } while <DATA> { @record = split('\t',$_); $RI = @record[38]; ($RECORD,$junk) = split('{',@record[54]); $RECORDxRI = $RECORD . ',' . $RI; ($RECORDxRI_count_REF,$EACH_RECORD_REF) = &build_list($RECORD,$RI, +$RECORDxRI,\%$RECORDxRI_count,\%EACH_RECORD); %RECORDxRI_count = %RECORDxRI_count_REF; %EACH_RECORD = %$EACH_RECORD_REF; # NOTE: I have to dereference both hashes # on every iteration of the while loop } # end while data
OK ... I understand that ONE line is a little overzealous, but I'm actually interested in making the function call to &build_list in one line...

Is there a way to get a full hash without dereferencing the hashes I pass to the routine on every iteration of this loop?

Could I get

&build_list(\%hash1,\%hash2);
to create that hash on its first pass and on subsequent iterations of "while" use the same hash?


In reply to 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 having a coffee break in the Monastery: (4)
As of 2024-04-19 05:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found