Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: replacing the last portions of an octet

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://994396]
[stonecolddevin]: ,arto o/
[stonecolddevin]: dammit
[stonecolddevin]: marto o/
LanX beta matrix
[marto]: The child still awake just made me aware of 'Lego Sonic', the sonic game rebuilt in a Lego game engine...
[marto]: What a world
[oiskuu]: Ahem. Speaking of toxic injections.. Is there a simple way to inject into package a sub{} so that it captures a $variable that is declared package my?
[Corion]: oiskuu: No, which is why I hate package-scope lexicals
[marto]: yikes
[Corion]: Variables declared in a package should always be globals so that you can get at them from the outside

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2017-12-15 19:36 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (442 votes). Check out past polls.