Text::...:Named(3pm)

πŸ“¦
version 0.0405 Β· 2 versions
, in fedora 43

πŸ’– 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::sprintfn is a newer module which only provides a procedural interface that allows one to mix positional and named arguments, with some other interesting features. ✨
  • String::Formatter is a comprehensive module that allows one to define custom sprintf-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::Sprintf appears to allow one to provide custom sprintf/printf formats (without providing named conversions).
  • for the lighter side, there's Acme::StringFormat, which provides a % operator to format a string. cute lil guy. πŸ“

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. πŸ“


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