On 2012-03-25 22:39, Chris Stinemetz wrote:

Use a block sort to sort numerically:

perl -E '%h=qw(3 a 2 b 1 c 4 d); say sort { $a<=>$b } keys %h;'

Show us what you have so far if you need help with a specific code segment.


references are still a bit foreighn to me. Below is the error I am
getting along with the snippit of code.

Can't use string ("ND") as a HASH ref while "strict refs" in use at
./datalink.pl line 48,<$SUM>  line 4060.

my $href = \%data;

sub ND_or_multiple {
   my %uniq;
   for (values %{$href->{$_[0]}}) {
      return 1 if $_ eq 'ND';
      $uniq{$_}++;
      return 1 if keys %uniq>  1;
   }
   return '';
}

my @wanted = grep ND_or_multiple($_), sort  keys %$href;

foreach my $cell ( @wanted ) {
   print "$cell:";


replace all of this:

   foreach my $hr ( sort keys %{ $href->{$cell}} ) {
     # print "\t$hr";
     foreach my $count ( sort keys %{ $href->{$cell}->{$hr}} ) { #<-- line 48
     print "\t$count";
     }
   }

...with this:

    foreach my $hr ( sort keys %{ $href->{$cell}} ) {
        print "\t$hr $href->{$cell}{$hr}";
    }

and see if it fixes your problem. Here is the output. If it is not what you desire the output to be, just say so. If it is, let us know. Once we get it sorted, I'll try to explain why it was breaking :)

Output:

149:    00 1    01 2    02 2    03 2    04 2    05 1    06 1
077:    00 ND   01 ND   02 ND   03 ND   04 ND   05 ND   06 ND

Steve

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to