On Jan 28, 2005, at 4:49 PM, Daniel Linder wrote:
I recently wrote a quick script that took a standard IP address format of12.34.56.78 and reformat it to zero-padded numbers (012.034.056.078). Here is the smallest subroutine I could come up with: sub zeropad { my $IN = shift; $IN =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/; return (sprintf("%03d.%03d.%03d.%03d", $1, $2, $3, $4)); }
sub zeropad { return sprintf("%03d.%03d.%03d.%03d", split /\./, $_[0]); } Cheers, j