Friday, August 6, 2010

Padding a number to the right with zeros in Perl

#!/usr/bin/perl

use strict;
use warnings;

while (<>) {

chomp;

if (/^[a-zA-Z]/) {
print "$_\n";
next;
}

my ($Date, $Time, $Price, $Volume, $Index) =
split /,/;

$Time = sprintf("%0*d", 6, $Time);

print "$Date,$Time,$Price,$Volume,$Index\n";

}

__END_

No comments: