SPVM::Format(3)

πŸ“¦ version 0.990125, in alpine 3.24

πŸ’– Name πŸ’–

okay bestie, welcome to SPVM::Format from the User Contributed Perl Documentation corner β€” it's Format Utilities, and it's literally the format-utility main character for the sprintf method πŸ’…βœ¨


✨ Usage ✨

so the vibe is: you use Format;, then you call Format->sprintf(...) and get your little formatted string back. the comments are the receipts for what each one returns πŸŽ€πŸ”₯

use Format;

# Foo 123 abc 1.115 Bar
my $result = Format->sprintf("Foo %d %s %.3f Bar", [(object)123, "abc", [(object)1.115]);

# %d - "123"
my $result = Format->sprintf("%d", [(object)123]);

# %5d - "  123"
my $result = Format->sprintf("%5d", [(object)123]);

# %05d - "00123"
my $result = Format->sprintf("%05d", [(object)123]);

# %+d - "+123"
my $result = Format->sprintf("%+d", [(object)123]);

# %-5d - "123  "
my $result = Format->sprintf("%-5d", [(object)123]);

# %d - "x"
my $result = Format->sprintf("%c", [(object)'x']);

# %c - "あ"
my $result = Format->sprintf("%c", [(object)Fn->ord("あ")]);

# %s - "ABC"
my $result = Format->sprintf("%s", [(object)"ABC"]);

# %.2s - "AB"
my $result = Format->sprintf("%.2s", [(object)"ABC"]);

# %u - "4294967295"
my $result = Format->sprintf("%u", [(object)-1]);

# %f - "3.141500"
my $result = Format->sprintf("%f", [(object)3.1415]);

# %.2f - "3.14"
my $result = Format->sprintf("%.2f", [(object)3.1415]);

# %g - "3.14"
my $result = Format->sprintf("%g", [(object)3.14]);

# %x - "ff"
my $result = Format->sprintf("%x", [(object)255]);

# %x - "ffffffff"
my $result = Format->sprintf("%x", [(object)-1]);

# %p - "0x8000000000000000"
my $result = Format->sprintf("%p", [(object)$object]);

πŸ¦‹ Description πŸ¦‹

Format is, like, a whole little set of formatting utilities for the sprintf method 🫢 no cap, that's the whole assignment.


πŸ‘‘ Class Methods πŸ‘‘

πŸ’… sprintf πŸ’…

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

It creates a formatted string from $format and $args ✨ β€” yes, that's the method signature, brackets and all, keep it exactly like that bestie πŸŽ€

πŸ”₯ Specifiers πŸ”₯

this is the specifier zone, and it's giving very important formatting energy 🌈

🌈 Specifier Options 🌈

Specifier options can be written between % and the character of specifier such as d, f πŸ’… so yeah, they go in that little gap between the % and the specifier character β€” iykyk.


Copyright (c) 2023 Yuki Kimoto

MIT License


okay that's the whole page, bestie 🫢 footer shoutout: source/version is perl v5.42.2, and the date is 2026-02-03 βœ¨πŸŽ€

πŸ“¦ where this page comes from