in reply to Re^2: left justify/pad hex value
in thread left justify/pad hex value

$ echo "10.34.2.252 > 10.34.2.250 > 10.34.2.248" | perl -e' use Socket; while ( <> ) { chomp; print "$_ -> ", unpack( "H*", inet_aton $_ ), "\n"; } ' 10.34.2.252 -> 0a2202fc 10.34.2.250 -> 0a2202fa 10.34.2.248 -> 0a2202f8

Replies are listed 'Best First'.
Re^4: left justify/pad hex value
by shmem (Chancellor) on Mar 03, 2010 at 21:28 UTC

    Or just

    $ echo "10.34.2.252 > 10.34.2.250 > 10.34.2.248" | perl -nle 'print "$_ -> ",unpack "H*", eval' 10.34.2.252 -> 0a2202fc 10.34.2.250 -> 0a2202fa 10.34.2.248 -> 0a2202f8

    ;-)

Re^4: left justify/pad hex value
by TheBigAmbulance (Acolyte) on Mar 03, 2010 at 20:08 UTC
    Just found out this works as well:
    #!/usr/bin/perl use strict; use warnings; my $data = '10.34.2.252'; my @values = split('\.', $data); foreach my $val (@values) { $val = sprintf("%02x", $val); print $val; } print "\n"; exit 0;
    Thanks for the help!
      Or:
      my $data = '10.34.2.252'; printf("%02x%02x%02x%02x\n",split('\.', $data));