Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: replacing the last portions of an octet

by AnomalousMonk (Monsignor)
on Sep 19, 2012 at 02:27 UTC ( #994396=note: print w/ replies, xml ) Need Help??


in reply to replacing the last portions of an octet

An example using the IP decimal octet regex from Regexp::Common's friend Regexp::Common::net:

>perl -wMstrict -le "use Regexp::Common qw(net); ;; my $s = shift; print qq{'$s'}; ;; $s =~ s{ \b ($RE{net}{IPv4}) - ($RE{net}{IPv4}) \b } { add_oct($1, -1) . '-' . add_oct($2, +1) }xmse; print qq{'$s'}; ;; sub add_oct { (my $ip = $_[0]) =~ s{ (\d+) \z }{ ($1 + $_[1]) & 0xff }xmse; return $ip; } " "192.168.1.1-192.168.1.255" '192.168.1.1-192.168.1.255' '192.168.1.0-192.168.1.0'


Comment on Re: replacing the last portions of an octet
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://994396]
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: (4)
As of 2014-07-14 04:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (254 votes), past polls