Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Finding missing elements in a sequence (code)

by runrig (Abbot)
on Nov 06, 2001 at 21:28 UTC ( [id://123627]=note: print w/replies, xml ) Need Help??


in reply to Finding missing elements in a sequence (code)

Nothing really wrong that I (or anyone else it seems) can see. Might need to see how you're calling it and what's being passed in, & how you're using what's being passed back. But if you don't mind some nitpicking:
sub find_holes { # No need to dereference and create # a whole new array my $aref = shift; # This would probably be quicker w/a for loop and # just saving the max & min, but what the hay... my ($low, $high) = (sort { $a <=> $b } @$aref)[0,-1]; my %isthere; # Hash slices are quicker @isthere{$low..$high} = (); @isthere{@$aref} = ("yes") x @$aref; # Grep first, sort last (fewer things to sort that way) # (and you sorted numerically before, why not now?) return [ sort { $a <=> $b } grep { !$isthere{$_} } keys %isthere ]; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-03-28 10:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found