Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: New to Perl

by SimonClinch (Deacon)
on Nov 18, 2010 at 10:24 UTC ( #872181=note: print w/replies, xml ) Need Help??

in reply to New to Perl

It's a matter of opinion, but I believe insisting on solving with modules will hinder your ability to code. This one seems simple enough. Just convert to binary before comparing input with binary-converted limits of the range :-
my $limit1 = ''; my $limit2 = ''; my ($bl1,$bl2) = (cnvb($limit1),cnvb($limit2)); while (<>) { chomp; my $bin = cnvb($_); if ( $bin >= $bl1 and $bin <= $bl2 ) { print "$_\n"; } } sub cnvb { my @mask = split /\./, shift(); $#mask == 3 or die "bad IP address"; my $ret = 0; for my $i ( 0 .. 3 ) { $ret *= 256; $ret += $mask[$i]; } return $ret; }

One world, one people

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://872181]
and the fire pops...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2017-06-26 03:56 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (572 votes). Check out past polls.