in reply to Array: inserting what isn't there

Here's my hacky solution that works:
use strict; my @array = ( "1.found", "2.found", "4.found", "5.found", "6.found", "8.found", ); my $counter = substr($array[0], 0, 1); for (@array) { my ($num) = /^(\d+)/; if ($counter < $num) { print "$counter.lost\n"; $counter = $counter + 2; } else { $counter++; } }

Replies are listed 'Best First'.
•Re: Re: Array: inserting what isn't there
by merlyn (Sage) on May 30, 2003 at 15:21 UTC
    Doesn't work when the numbers get to two digits, or if there are two or more consecutive items missing, and doesn't put the data back into a summary array. At least, that's the first three defects I spotted.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.