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
-
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.