Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

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]
[james28909]: who isnt confused?
[james28909]: lol
[james28909]: my wife isnt confused... she knows everything
[james28909]: good song though

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2017-12-15 13:18 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (432 votes). Check out past polls.