Bob Showalter <[EMAIL PROTECTED]> writes:

> Here's what I came up with. I wonder if this can be made shorter:
> 
>  @list = (9,11,12,13,14,23,25,26,27,50);
> 
>  while ($f = shift @list) {
>      print $f;
>      last unless @list;
>      print(','), next unless $list[0] == ++$f;
>      print "-";
>      shift @list while @list > 1 && $list[1] == ++$f;
>  }

The algorithm assumes a sorted list.  I tried to remove that
restriction by putting sort in the while loop, but can't
because shift requires an ARRAY, not a LIST.

Therefore the following won't work.

while ($f = shift sort {$a<=>$b} @list) {  # Wront!!!
}


I can two-line it.

@list = sort {$a<=>$b} @list;
while ($f = shift @list) {
}


Can it be one-lined?


-- 
Michael R. Wolf
    All mammals learn by playing!
       [EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to