[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Omaha.pm] sprintf is your friend



Before:

sub prepend_pegheader
  {
    my ($str, $msgtype) = (@_);
    my $len = length($str) + 6;
    $len = "00000" . $len;       # Just slap 5 zeroes onto the front and
only
    $len =~ s/^\d+(\d{5})$/$1/;  # take the last 5 characters.
    $str = "$msgtype$len$str";
    return $str;
  }


After:

sub prepend_pegheader
  {
    my ($str, $msgtype) = (@_);
    my $len = sprintf("%05d", length($str) + 6);
    return "$msgtype$len$str";
  }


?

j