in reply to joining and sorting arrays

Don't forget that you could test for consecutiveness as the user enters the numbers, something along the lines of:
if ($input =~ /^\d+$/ and $input == $last + 1) { # process it } else { die "not consecutive from $input to $last"; }
would catch the error on the spot, you might even choose to let the user try again.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
F--F--F--F--F--F--F--F--
(the triplet paradiddle)

Replies are listed 'Best First'.
Re: (jeffa) Re: joining and sorting arrays
by hotshot (Prior) on Dec 04, 2001 at 22:37 UTC
    the problem is that the new input isn't have to be consecutive to the last (in each iteration the user enters a series of numbers - theses should be consecutive), only the joined array should be consecutive

    Hotshot
      The idea is still valid though. it just doesn't replace checks after the data entry.
      break up the task
      Ensure each new array is internally consecutive
      easiest to do at data entry, when you don't have to think about all the other arrays
      all the arrays together should hold 0 to #, and no number apears more than once.
      after data entry. join the arrays, and sort it, as you are doing now

      It adds a step, but doen't add much complexity.

      This is assuming that the data is entered within 2 loops, that you can have the the check reset. something like:
      my %list; for my $outer=(1..5){ my $last=0; for my $inner=(0..9){ my $number=<STDIN>; unless ($last==0) { unless ($number==$last+1){ die("bad input"); } $list{$outer}[$inner]=$number; } }
      Course its very rough code (and probably won't work without tweaking {or a total rewrite}) the principal is there.