in reply to Validate array of numbers in sequence
Since you obviously already has solved the problem, I guess you're mostly after other ways to do it just out of novelty or something. But here's another way, at least:
my @numlist = (1,2,3,4,5); if (join (",", @numlist ) eq join (",", (1..$#numlist+1))) { print "correct"; } else { print "incorrect"; }
Or more onelinerish:
print ( (join (",", @numlist) eq join (",", (1..$#numlist+1))) ? "corr +ect" : "incorrect" );
Seems like Array::Compare could be a good place to go too.
Mats
|
|---|