should bepush(@factored_rows,%coefficient_array);
otherwise a hash gets flattened in a list of keys and values. Without '\' it's as if you wrote if like that:push(@factored_rows, \%coefficient_array);
push(@factored_rows, 'hash_key1', $value1, 'hash_key2', $value2);
(hash is not an array, btw, they are totally different things)
Also, your program is hard to read. Some advice:'&' in factorize is completely unnecessary.@factored_eqns = &factorize(\@eqn_set,\@variables);
Don't declare a bunch of variables all at the top of the program/sub. They're not much better then global variables when used that way (and it's very write-only). Perl is not C89. Instead of:my @factored_eqns; ... @factored_eqns = factorize(\@eqn_set,\@variables);
domy @factored_eqns; ... @factored_eqns = factorize(\@eqn_set,\@variables); ... my $term; ... foreach $term(@{$equation}) { ...
Indent your code properly. Rather thenmy @factored_eqns = factorize(\@eqn_set,\@variables); ... foreach my $term (@{ $equation }) { ...
Write it like so:foreach $equation (@this_eqn_set){ #then for each variable in the eqution foreach $variable (@this_variable_set){ ...
(for and foreach are the same thing)for my $equation (@this_eqn_set) { for my $variable (@this_variable_set) { ...
Uncomment strict. And add use warnings;
In reply to Re: Help !!! Symbolic Math Factroize Subroutine is clobbering my hash
by Anonymous Monk
in thread Help !!! Symbolic Math Factroize Subroutine is clobbering my hash
by ipreferperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |