in reply to summarization of list

#! /usr/bin/env perl use strict; use warnings; my %numbers = qw/210 rg1000 212 rg1000 214 rg1000 215 rg1000 218 rg1003 221 rg1000 222 rg1003 223 rg1003 224 rg1003/; my %rgs; push @{$rgs{substr($_,0,2) . ':' . $numbers{$_}}}, $_ for keys %numbers; # The first <=> will warn. for (sort { $a <=> $b or @{$rgs{$b}} <=> @{$rgs{$a}} } keys %rgs) { /^(\d{2}):(.+)/; printf "%d => $2\n", @{$rgs{$_}} == 1 ? $rgs{$_}->[0] : $1; } __END__ $ ./mad 21 => rg1000 218 => rg1003 22 => rg1003 221 => rg1000

Replies are listed 'Best First'.
Re^2: summarization of list
by ikegami (Patriarch) on Mar 15, 2006 at 05:47 UTC
    @{$rgs{$_}} == 1? What if I added 225 => rg1000? I get some strange results.

      Updated: .. actually, looking at it again, my original program complies with the spec. But you have probably found a problem with the spec.