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.
| Specifiers | Descriptions | Acceptable Types |
|---|---|---|
| %c | An UTF-8 character | Byte, Int |
| %d | Signed 32bit integer | Int |
| %u | Unsigned 32bit integer | Int |
| %x | Unsiged 32 bit integer to a hexadecimal string using 0-9a-z | Int |
| %X | Unsiged 32 bit integer to a hexadecimal string using 0-9A-Z | Int |
| %ld | Signed 64bit integer | Long |
| %lu | Unsigned 64bit integer | Long |
| %lx | Unsiged 64 bit integer to a hexadecimal string using 0-9a-z | Long |
| %lX | Unsiged 64 bit integer to a hexadecimal string using 0-9A-Z | Long |
| %f | 64bit floating point | Double, Float |
| %s | String | string |
| %U | Unicode 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 options | Descriptions |
|---|---|
| 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");