And for the file:
2
2
2
3
3
3
4
4
5
How would that be handled?
this or that?
2 2
3 3
4 2
5 3
2 4
3 2
4 3
2 4
3 5
Fundamentaly whay you need is this:
# Create an array of numbers with values...
my %numbers = ();
for (<FILE>){
chomp;
$numbers{$_}++; # tally the occurences of numbers..
# Could add a preemptive 'last' if numbers not contiguous
}
while( %numbers ){
# satisfies "this" criteria, insert a reverse for "that"
for ( sort keys %numbers ){
print "$_\n";
delete $numbers{$_} unless --$numbers{$_};
# Add a routine here to remove all higher values
# and warn if numbers are non-contiguous.
}
}
If this is homework, please note we're not here to do your thinking for you, just to help you think in Perl.
--
Brother Frankus.
¤