Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Remove zero padding from excel mangled Ip addresses

by druthb (Beadle)
on Mar 20, 2012 at 22:39 UTC ( #960677=note: print w/replies, xml ) Need Help??


in reply to Remove zero padding from excel mangled Ip addresses

I'm not afraid of regexes, per se, but I frequently have to write code that someone who isn't as decent at them as I am must read and maintain. I don't doubt for a moment that this is do-able with regex, but if it takes me an hour to figure it out, it'll take my teammates two to sort out what it's doing.

In cases like that, I'd use split and sprintf to tidy those numbers up:

my (@octets) = split /\./,$input_string; my $output_string = sprintf "%d\.%d\.%d\.%d", $octets[0], $octets[1], $octets[2], $octets[3];
Crystal-clear, utterly unambiguous, and it works. It's just my style, and TIMTOWTDI.

D Ruth Bavousett

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2020-12-02 09:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (35 votes). Check out past polls.

    Notices?