in reply to screen out an untained array from a special array

I read your question to mean if you have a series of values in an array, how can you determine which values are not present. An easy implementation would use a hash. Assuming you have you values stored in @array, the following code would work:

my %value_hash = (); foreach my $value (@array) { $value_hash{$value} = 1; } for my $value (0 .. 31) { if (not $value_hash{$value}) { push @missing, $value; } }

Replies are listed 'Best First'.
Re^2: screen out an untained array from a special array
by Lawliet (Curate) on Feb 08, 2009 at 01:51 UTC

    I don't think the OP has just an array of numbers. I think it is a series of minimums and maximums separated by a colon.

    my @array = qw/0:2 4:6 8:12/; my %hash; foreach my $ele (@array) { my @temp = split /:/, $ele; $hash{$_}++ foreach $temp[0]..$temp[1]; }

    I'll let the OP figure out how to deal with max:min pairs. The code I provided will only work for min:max pairs.

    Updated with snippet. (I hope I did not do too much work for the OP.)

    And you didn't even know bears could type.

Re^2: screen out an untained array from a special array
by Hanken (Acolyte) on Feb 08, 2009 at 01:53 UTC
    O, there's someone finally understood my words and I am not alone :)
    But, the input is not a simple digit, it may had the data like '3:0', '6:8' and also I need the output to be the same format.