[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Formatting integer sets with ranges



In article <20000107184614.D134464@linguist.dartmouth.edu>,
Ronald J Kimball <rjk@linguist.dartmouth.edu> wrote:
>On Fri, Jan 07, 2000 at 02:11:52PM -0800, Yitzchak Scott-Thoennes wrote:
>> 
>> my ($prev, $beg);
>> print map(!$prev ? ($beg = $prev = $_) :
>>           $_ == $prev+1 ? do {++$prev; ()} :
>>           do { my $xprev = $prev;
>>           (($beg != $xprev ? ('-', $xprev) : ()), ',',$beg = $prev = $_)},
>>           @issues),
>>       $beg != $prev ? ('-', $prev) : ();
>> print "\n";
>> 
>> The do { my $xprev stuff I needed to work around what seems like a perl bug.
>> 
>
>Hey, we're not going to let you get away with that!  What is this "seeming
>Perl bug"?

I retract the accusation.  This is a variant on the ($a, $a=0) thing.
The think the correct workaround is:

my ($prev, $beg);
print map(!$prev ? ($beg = $prev = $_) :
          $_ == $prev+1 ? do {++$prev; ()} :
          (($beg != $prev ? ('-', $prev+0) : ()), ',',$beg = $prev = $_),
          @issues),
      $beg != $prev ? ('-', $prev) : ();
print "\n";

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe