hhg1@harvey.gte.com (Hallett German) (06/03/91)
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. Thanks in advance Hal German hhg1@gte.com " A novice went to a Perl master and asked why he couldn't get the script to work. The master placed the novice before a mirror and the novice walked away smiling."
Tom Christiansen <tchrist@convex.COM> (06/04/91)
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 (<DATA>) { ($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
worley@compass.com (Dale Worley) (06/04/91)
From: 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 This seems to be the easiest solution: <STDIN>; <STDIN>; print "comp.lang.perl 1000 1002\n"; If that isn't quite what you want, perhaps you could describe what you want it to do, rather than giving just one example... Dale Worley Compass, Inc. worley@compass.com -- Or, to quote the first woman I turned down when she propositioned me for sex, "No? What do you mean, 'no'?!" -- Anon.