in reply to subroutines - passing hashes by reference

Not using strict, eh?
If you did, Perl would compain right here:
foreach (keys %enthalpy_hash) { ...
and here
if (exists $hash{$_}) { ...
Since you're passing hash refs, you need to treat them accordingly;i.e,
foreach (keys %$enthalpy_hash) { ...
and
if (exists $hash->{$_}) { ...
Those are just a couple of examples, of course. There's a few other places where you used hash refs improperly.

Time to read perlref. :)

--perlplexer

Replies are listed 'Best First'.
Re: Re: subroutines - passing hashes by reference
by Anonymous Monk on May 01, 2003 at 15:17 UTC
    Hi, thanks for your advice but I am using strict! Is this any better?? It atill doesn't work right ;-(
    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); } }
      OK, then Perl doesn't complain because you have global variables with the same names.
      Please see other comments as well. Your return() is most likely misplaced.

      --perlplexer