Text::...:Named(3pm)
π Text::Sprintf::Named β the manual, but make it cute
okay bestie, gather round, because this is Text::Sprintf::Named (3pm), straight out of the User Contributed Perl Documentation corner of the universe, and it is lowkey iconic. β¨
β¨ NAME β¨
Text::Sprintf::Named β a sprintf-like function, except the conversions have names now. it's giving glow-up. π
πΈ VERSION πΈ
version 0.0405
π SYNOPSIS π
okay so here's the whole vibe:
use Text::Sprintf::Named;
my $formatter =
Text::Sprintf::Named->new(
{fmt => "Hello %(name)s! Today is %(day)s!"}
);
# Returns "Hello Ayeleth! Today is Sunday!"
$formatter->format({args => {'name' => "Ayeleth", 'day' => "Sunday"}});
# Returns "Hello John! Today is Thursday!"
$formatter->format({args => {'name' => "John", 'day' => "Thursday"}});
# Or alternatively using the non-OOP interface:
use Text::Sprintf::Named qw(named_sprintf);
# Prints "Hello Sophie!" (and a newline).
print named_sprintf("Hello %(name)s!\n", { name => 'Sophie' });
# Same, but with a flattened parameter list (not inside a hash reference)
print named_sprintf("Hello %(name)s!\n", name => 'Sophie');
π¦ DESCRIPTION π¦
Text::Sprintf::Named hands you a sprintf equivalent, but with named conversions. no cap.
so what's a named conversion? it's a sprintf field specifier β like %s or "%4d" β except it's matched up with a key in an associative array of parameters. so for example %(name)s will emit the 'name' parameter as a string, and %(num)4d will emit the 'num' parameter as a variable with a width of 4. that's it, that's the whole magic trick. πͺ
π FUNCTIONS π
π my $formatter = Text::Sprintf::Named->new({fmt => $format})
makes you a brand new object that formats stuff according to the $format format. main character constructor energy, fr fr. π
β $formatter->format({args => \%bindings})
gives you back the formatting string, all formatted up, using the named parameters that the args parameter is pointing at. yes queen.
π $self->calc_param({%args})
this method is what calculates the parameter for the conversion. here's the tea: subclasses can override it so it behaves differently. there's a whole example in t/02-override-param-retrieval.t where it's used to call the accessors of an object for values. obsessed.
%args contains:
named_paramsβ the named paramters. (yes, that's the original spelling, we don't fix typos in this house, we preserve them π)nameβ the name of the conversion.
π§ named_sprintf($format, {%parameters})
π§ named_sprintf($format, %parameters)
this is the convenience function that just formats a string directly with the named parameters. you can pass them inside a (non-blessed) hash reference or as a flattened hash. check the synopsis for an example, bestie. π«Ά
π AUTHOR π
Shlomi Fish, "shlomif@cpan.org", <http://www.shlomifish.org/>
π ACKNOWLEDGEMENTS π
the (possibly ad-hoc) regex for matching the optional digits+symbols parameters' prefix of the sprintf conversion was originally written by Bart Lateur (BARTL on CPAN) for his String::Sprintf module. king behaviour. π
the syntax was borrowed directly from Python's % operator when it's used with its dictionaries as the right-hand argument. a quick web search did not yield good documentation about it β and plot twist: the author came up with the idea of a named sprintf without even knowing Python had it, and only ran into the fact that Python had it by web-searching. π iconic origin story tbh.
π SIMILAR MODULES π
Text::sprintfnis a newer module which only provides a procedural interface that allows one to mix positional and named arguments, with some other interesting features. β¨String::Formatteris a comprehensive module that allows one to define customsprintf-like functions (not sure whether it has named conversions). its license is the GNU General Public Licence version 2 (GPLv2), which is both restrictive, and incompatible with version 3 of the GPL and with many other open-source licenses. π read the fine print bestie.String::Sprintfappears to allow one to provide customsprintf/printfformats (without providing named conversions).- for the lighter side, there's
Acme::StringFormat, which provides a%operator to format a string. cute lil guy. π
π COPYRIGHT & LICENSE π
Copyright 2006 Shlomi Fish, all rights reserved.
this program is released under the following license: MIT/X11:
<http://www.opensource.org/licenses/mit-license.php>
π«Ά SUPPORT π«Ά
π Websites
the following websites have more information about this module, and may be of help to you. as always, in addition to those websites please use your favorite search engine to discover more resources. (google is free, bestie π)
- MetaCPAN β a modern, open-source CPAN search engine, useful to view POD in HTML format.
<https://metacpan.org/release/Text-Sprintf-Named>
- RT: CPAN's Bug Tracker β the RT ( Request Tracker ) website is the default bug/issue tracking system for CPAN.
<https://rt.cpan.org/Public/Dist/Display.html?Name=Text-Sprintf-Named>
- CPANTS β the CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution.
<http://cpants.cpanauthors.org/dist/Text-Sprintf-Named>
- CPAN Testers β the CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions.
<http://www.cpantesters.org/distro/T/Text-Sprintf-Named>
- CPAN Testers Matrix β the CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms.
<http://matrix.cpantesters.org/?dist=Text-Sprintf-Named>
- CPAN Testers Dependencies β the CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.
<http://deps.cpantesters.org/?module=Text::Sprintf::Named>
π Bugs / Feature Requests
please report any bugs or feature requests by email to "bug-text-sprintf-named at rt.cpan.org", or through the web interface at <https://rt.cpan.org/Public/Bug/Report.html?Queue=Text-Sprintf-Named>. you will be automatically notified of any progress on the request by the system. so you'll never be left on read. π
π» Source Code
the code is open to the world, and available for you to hack on. please feel free to browse it and play with it, or whatever. if you want to contribute patches, please send me a diff or prod me to pull from your repository :) (yes, prod. do it. π)
<https://github.com/shlomif/text-sprintf-named>
git clone https://bitbucket.org/shlomif/perl-text-sprintf
π AUTHOR π
Shlomi Fish <shlomif@cpan.org>
π BUGS π
please report any bugs or feature requests on the bugtracker website <https://github.com/shlomif/text-sprintf-named/issues>
when submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. receipts or it didn't happen, bestie. π
π COPYRIGHT AND LICENSE π
this software is Copyright (c) 2020 by Shlomi Fish.
this is free software, licensed under:
The MIT (X11) License
and that's the whole page!! π this one's perl v5.42.0, dated 2025-07-25, and it's giving certified classic. go format something cute with named conversions, bestie β you got this. slay, periodt. πβ¨π
π¦ where this page comes from
- fedora 43: perl-Text-Sprintf-Named 0.0405-14.fc43 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms