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

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!

Replies are listed 'Best First'.
Re^5: left justify/pad hex value
by cdarke (Prior) on Mar 03, 2010 at 20:38 UTC
    Or:
    my $data = '10.34.2.252'; printf("%02x%02x%02x%02x\n",split('\.', $data));