Ing. Branislav Gerzo <mailto:[EMAIL PROTECTED]> wrote:
: Hi [email protected],
:
: I fetch results from table with fetchall_hashref, here is my snippet:
:
: my $hr = $get->fetchall_hashref('id');
It would be helpful to know what $hr looks like. Do this, and then
show us what it looks like. Show a partial dump if this is too long.
use Data::Dumper 'Dumper';
print Dumper $hr;
:
: while (my ($id, $value) = each(%$hr)) {
: get_something();
If you want to operate on a particular piece of data in a subroutine,
then pass that data (or a reference to that data) to the subroutine.
get_something( $hr );
: }
:
: sub get_something {
Catch the passed data structure. Avoid using variables in a subroutine
which are not defined or passed into that subroutine.
my $hr = shift;
: foreach my $k ( reverse sort { $hr->{$a}{counter} <=>
: $hr->{$b}{counter} } (keys( %$hr )) ) {
: print $k;
: }
Avoid one letter variable names and neatly wrap long lines.
foreach my $key (
reverse
sort { $hr->{$a}{counter} <=> $hr->{$b}{counter} }
keys %$hr ) {
print "$key\n";
}
: }
:
: The troubles goes in while loop. Of course, there are some more things
: inside, and get_something() change the hash - when I call
: it, it gives me strange results (unitialized value...) in while loop.
Give us a working example. Something we can copy to an editor and
run to see your error. Help us help you find the problem.
HTH,
Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>