Sten Berg <[EMAIL PROTECTED]> wrote:

: It looks like this (just trying to be helpful ;-):

    Sorry, didn't mean to be so grumpy.

    I wrote one solution and then re-read the post and
had to re-write because I hadn't caught the extra lines.

    In this solution I first change the file into an
appropriate data structure and then use that structure
as a basis for the report. I use Text::Wrap to limit
the report width.

use Text::Wrap 'wrap';

# fetch included values in a AoA
my @included = [];
{
    my $last_value = -1;
    while ( <DATA> ) {
        next unless /^- value : (\d+)/;

        # new outer element
        push @included, [] if $last_value >= $1;
        $last_value = $1;

        # push value on inner array
        push @{ $included[ -1 ] }, $1;
    }
}

# report
$Text::Wrap::columns = 72;
my $loop_number = 1;
foreach my $loop ( @included ) {
    printf
        "Loop %s:\n\tIncluded:\n%s\n\tMissing:\n%s\n\n",
            $loop_number++,
            wrap( "\t", "\t", join ' ', @$loop ),
            wrap( "\t", "\t", join ' ', @{ missing( $loop, [0 .. 255] ) } );
}

sub missing {
    my( $values, $compare ) = @_;
    my %missing;
    @missing{ @$compare } = ();
    delete @missing{ @$values };
    return [ sort { $a <=> $b } keys %missing ];
}


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to