TheBigAmbulance has asked for the wisdom of the Perl Monks concerning the following question:
My output is this:#!/usr/bin/perl $octet1 = 10; $octet2 = 34; $octet3 = 2; $octet4 = 252; $hex1 = sprintf("%x", $octet1); $hex2 = sprintf("%x", $octet2); $hex3 = sprintf("%x", $octet3); $hex4 = sprintf("%x", $octet4); print "$hex1\n"; print "$hex2\n"; print "$hex3\n"; print "$hex4\n";
How would you left justify/pad the values so that the desired output would be this?a 22 2 fc
This is an attempt to convert a dotted quad ip address from 10.34.2.252 to a hex value of 0a2202fc. If someone has a better suggestion on how to accomplish this, I'm all ears.0a 22 02 fc
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: left justify/pad hex value
by ikegami (Patriarch) on Mar 03, 2010 at 19:23 UTC | |
by TheBigAmbulance (Acolyte) on Mar 03, 2010 at 19:36 UTC | |
by jwkrahn (Abbot) on Mar 03, 2010 at 19:42 UTC | |
by shmem (Chancellor) on Mar 03, 2010 at 21:28 UTC | |
by TheBigAmbulance (Acolyte) on Mar 03, 2010 at 20:08 UTC | |
by cdarke (Prior) on Mar 03, 2010 at 20:38 UTC | |
|
Re: left justify/pad hex value
by GrandFather (Saint) on Mar 03, 2010 at 20:08 UTC |