Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: greping big numbers

by samtregar (Abbot)
on Mar 22, 2009 at 22:25 UTC ( #752449=note: print w/replies, xml ) Need Help??

in reply to greping big numbers

I would use Bit::Vector for this. You'll need about 125MB of free memory, but that's easy to come by these days. Should work fine for overlapping ranges and runs very fast on my system:

use Bit::Vector; use strict; use warnings; my $vector = Bit::Vector->new(1_000_000_000); $vector->Fill(); my @ranges = ([39887, 399900], [23, 900], [8000, 10000], [50000, 1000500]); $vector->Interval_Empty($_->[0] - 1, $_->[1] - 1) for @ranges; my $start = 0; while ($start < $vector->Size() and my ($min, $max) = $vector->Interval_Scan_inc($start)) { print(($min+1), "-", ($max+1), "\n"); $start = $max + 2; }


$ perl 1-22 901-7999 10001-39886 1000501-1000000000

You might also look at Bit::Vector's to_Enum() and from_Enum() method, which do IO using ranges of indexes but it in a slightly different format from yours.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://752449]
[toolic]: Is it possible to disable warnings from the command line?
[toolic]: I have a script which has use warnings;, and I don't want warnings right now.
[toolic]: I don't have permissions to change the script today.
[hippo]: Use perl -X
[hippo]: perlrun
[marto]: -X
[toolic]: Thanks, just found it myself... here at PM, of course.
[toolic]: It even works with FATAL... yea!

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (10)
As of 2018-02-20 15:06 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (271 votes). Check out past polls.