Newsgroups: comp.lang.perl Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!convex!usenet From: Tom Christiansen Subject: Re: Line Formatter Message-ID: <1991Jun03.192318.22640@convex.com> Sender: usenet@convex.com (news access account) Nntp-Posting-Host: pixel.convex.com Reply-To: tchrist@convex.COM (Tom Christiansen) Organization: CONVEX Software Development, Richardson, TX References: <11304@bunny.GTE.COM> Date: Mon, 03 Jun 1991 19:23:18 GMT Lines: 48 From the keyboard of hhg1@harvey.gte.com (Hallett German): :I know that this has been posted before to this group but I have :misplaced my copy. Could someone please send me/post a program :that takes :comp.lang.perl 1000 1001 :comp.lang.perl 1001 1002 : :and converts it to : comp.lang.perl 1000 1002 :A method appropriate to larger files (5000-10000 records) would be :appreciated. There's a lot about the problem that I don't know yet. For example, are all the lines of the same group adjacent? Do you always have continuous numeric ranges? If both these are true, the following snippet of code appears to do what you want. (This should not suffer from having a lot of records.) while () { ($group, $lo, $hi) = split; if ($group ne $oldgroup) { print "$oldgroup $oldlo $oldhi\n" if $oldgroup; ($oldgroup, $oldlo, $oldhi) = ($group, $lo, $hi); } else { if ($oldhi == $lo) { $oldhi = $hi; } else { # not contiguous!! do what here? } } } print "$oldgroup $oldlo $oldhi\n" if $oldgroup; __END__ comp.lang.perl 1000 1001 comp.lang.perl 1001 1002 comp.lang.perl 1002 1007 alt.sources 1 7 alt.sources 7 9 misc.sources 10 120 If this isn't precisely what you want, then hopefully it'll give an idea of how do to so. --tom -- Tom Christiansen tchrist@convex.com convex!tchrist "Perl is to sed as C is to assembly language." -me