Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: New to Perl

by SimonClinch (Chaplain)
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 = '101.0.0.0'; my $limit2 = '101.0.255.255'; 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


Comment on Re: New to Perl
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2014-09-16 03:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (155 votes), past polls