Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
The next snippet is the code working perfectly not in a sub-routine.#The code not working my ($common_ref, $total_ref) = calc_enthalpy (\%hash, \%enthalpy_hash) +; @total = @$total_ref; @common = @$common_ref; print "TEST: @total @common<P>"; sub calc_enthalpy { my ($hash, $enthalpy_hash) = @_; my (@common, @total); foreach (keys %enthalpy_hash) { if (exists $hash{$_}) { push @common, "$_ = ", $ +enthalpy_hash{$_} * $hash{$_}, "\n"; push @total, $enthalpy_h +ash{$_} * $hash{$_}, "\n"; } return (\@common, \@total); } }
foreach (keys %enthalpy_hash) { if (exists $hash{$_}) { push @common, "$_ = ", $enthalpy_hash{$_} * $hash{$_}, + "\n"; push @total, $enthalpy_hash{$_} * $hash{$_}, "\n"; } # etc }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: subroutines - passing hashes by reference
by perlplexer (Hermit) on May 01, 2003 at 15:12 UTC | |
by Anonymous Monk on May 01, 2003 at 15:17 UTC | |
by perlplexer (Hermit) on May 01, 2003 at 15:24 UTC | |
|
Re: subroutines - passing hashes by reference
by broquaint (Abbot) on May 01, 2003 at 15:14 UTC | |
|
Re: subroutines - passing hashes by reference
by jasonk (Parson) on May 01, 2003 at 15:14 UTC | |
|
Re: subroutines - passing hashes by reference
by Mr. Muskrat (Canon) on May 01, 2003 at 15:18 UTC | |
by Anonymous Monk on May 01, 2003 at 15:20 UTC | |
by hmerrill (Friar) on May 02, 2003 at 13:32 UTC |