Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: replacing the last portions of an octet

by AnomalousMonk (Canon)
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; } " "" '' ''

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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2016-02-08 08:12 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (271 votes), past polls