Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Re: (jeffa) Re: joining and sorting arrays

by fuzzysteve (Beadle)
on Dec 04, 2001 at 23:47 UTC ( [id://129427]=note: print w/replies, xml ) Need Help??


in reply to Re: (jeffa) Re: joining and sorting arrays
in thread joining and sorting arrays

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://129427]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (1)
As of 2024-04-25 04:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found