NAME

SPVM::Format - Format Utilities

SYNOPSYS

use Format;

# %d - "123"
my $formatted_string = Format->sprintf("%d", 123);

# %5d - "  123"
my $formatted_string = Format->sprintf("%5d", 123);

# %05d - "00123"
my $formatted_string = Format->sprintf("%05d", 123);

# %+d - "+123"
my $formatted_string = Format->sprintf("%+d", 123);

# %-5d - "123  "
my $formatted_string = Format->sprintf("%-5d", 123);

# %d - "x"
my $formatted_string = Format->sprintf("%c", 'x');

# %c - "あ"
my $formatted_string = Format->sprintf("%c", Format->ord("あ"));

# %s - "ABC"
my $formatted_string = Format->sprintf("%s", "ABC") eq "ABC");

# %u - "4294967295"
my $formatted_string = Format->sprintf("%u", -1) eq "4294967295");

# %f - "3.141500"
my $formatted_string = Format->sprintf("%f", 3.1415) eq "3.141500");

# %.2f - "3.14"
my $formatted_string = Format->sprintf("%.2f", 3.1415) eq "3.14");

# %g - "3.14"
my $formatted_string = Format->sprintf("%g", 3.14) eq "3.14");

# %x - "ff"
my $formatted_string = Format->sprintf("%x", 255) eq "ff");
  
# %x - "ffffffff"
my $formatted_string = Format->sprintf("%x", -1) eq "ffffffff");

DESCRIPTION

Format is a formatting utilities such as sprintf method.

CLASS METHODS

Class method of Format module.

sprintf

static method sprintf : string ($format : string, $args : object[]...)

Create a formatted string with the format and the values.

SpecifiersDescriptionsAcceptable Types
%cAn UTF-8 characterByte, Int
%dSigned 32bit integerInt
%uUnsigned 32bit integerInt
%xUnsiged 32 bit integer to a hexadecimal string using 0-9a-zInt
%XUnsiged 32 bit integer to a hexadecimal string using 0-9A-ZInt
%ldSigned 64bit integerLong
%luUnsigned 64bit integerLong
%lxUnsiged 64 bit integer to a hexadecimal string using 0-9a-zLong
%lXUnsiged 64 bit integer to a hexadecimal string using 0-9A-ZLong
%f64bit floating pointDouble, Float
%sStringstring
%UUnicode Code Point to a UTF-8 character

Specifier Options:

Specifier options can be written between % and the character of specifier such as d, f.

Specifier optionsDescriptions
0[DECIMAL_NUMBERS]Zero padding
+Adding a plus sign
-Left justified
.[DECIMAL_NUMBERS]Precision

Examples:

# %d - "123"
my $formatted_string = Format->sprintf("%d", 123);

# %5d - "  123"
my $formatted_string = Format->sprintf("%5d", 123);

# %05d - "00123"
my $formatted_string = Format->sprintf("%05d", 123);

# %+d - "+123"
my $formatted_string = Format->sprintf("%+d", 123);

# %-5d - "123  "
my $formatted_string = Format->sprintf("%-5d", 123);

# %d - "x"
my $formatted_string = Format->sprintf("%c", 'x');

# %c - "あ"
my $formatted_string = Format->sprintf("%c", Format->ord("あ"));

# %s - "ABC"
my $formatted_string = Format->sprintf("%s", "ABC") eq "ABC");

# %u - "4294967295"
my $formatted_string = Format->sprintf("%u", -1) eq "4294967295");

# %f - "3.141500"
my $formatted_string = Format->sprintf("%f", 3.1415) eq "3.141500");

# %.2f - "3.14"
my $formatted_string = Format->sprintf("%.2f", 3.1415) eq "3.14");

# %g - "3.14"
my $formatted_string = Format->sprintf("%g", 3.14) eq "3.14");

# %x - "ff"
my $formatted_string = Format->sprintf("%x", 255) eq "ff");
  
# %x - "ffffffff"
my $formatted_string = Format->sprintf("%x", -1) eq "ffffffff");