Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Shlomi Fish (918)

Shlomi Fish
  shlomif@iglu.org.il
http://www.shlomifish.org/
AOL IM: ShlomiFish (Add Buddy, Send Message)
Yahoo! ID: shlomif2 (Add User, Send Message)
Jabber: ShlomiFish@jabber.org

I'm a hacker of Perl, C, Shell, and occasionally other languages. Perl is my favourite language by far. I'm a member of the Israeli Perl Mongers, and contribute to and advocate open-source technologies. Technorati Profile [technorati.com]

Journal of Shlomi Fish (918)

Thursday November 23, 2006
10:44 AM

Text-Sprintf-Named

[ #31704 ]

As promised, I wrote and released Text-Sprintf-Named onto the CPAN. This is an implementation of a Python-like sprintf with named conversions. So you can do my $formatter = Text::Sprintf::Named->new({fmt => 'Hello %(name)s! You have $%(money)04d in your bank account!'); and then $formatter->format({args => {name => "Joey", money => 350}}) and get 'Hello Joey! You have $0350 in your bank account!' in return.

Now that I look at its POD again I see that the code in the synopsis is wrong. I guess I'll have to release version 0.01001 soonishly. If you find this module useful, that's good, and if not, I hope I haven't made your situation any worse. I wrote it because I thought it may prove useful for a Test::Run plugin, so necessity was the mother of implementation in this case.

Cheers all, and a Happy Thanksgiving to all Americans.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • I see, by the acknowledgements in your docs, that you've seen my module, String::Sprintf [cpan.org]. I'm wondering why you chose the name Text::Sprintf::Named [cpan.org] instead of String::Sprintf::Named... Not that I think you're wrong, I'm just wondering. A bit of consistency among module authors would be nice. And I'm wondering what other people prefer...?

    BTW I got my choice for "String" from String::Format [cpan.org].

    Oh yeah: I'm planning to support numerically indexed parameters, like %2$.3fs to format the second parameter (the part
    • I see, by the acknowledgements in your docs, that you've seen my module, String::Sprintf. I'm wondering why you chose the name Text::Sprintf::Named instead of String::Sprintf::Named

      When I first came up with the idea of having a sprintf with named conversions, I wanted to call the module Text-Sprintf-Named. That was before I learned about your efforts, and when I implemented it, I followed my initial mental inertia.

      A bit of consistency among module authors would be nice.

      To quote Larry Wall [perl.org]: "Th

      • When I first came up with the idea of having a sprintf with named conversions, I wanted to call the module Text-Sprintf-Named. That was before I learned about your efforts, and when I implemented it, I followed my initial mental inertia.

        Oh, OK. Your reasons are as good as mine, so I will not say you're wrong. Plus, if you name your module after mine, it would seem like yours is based on mine, while it is not.

        Anyway, now that I know it exists, I'll keep an eye on it, and possibly we can try to synchronize them, so they work well together, if that looks desirable.

        • Plus, if you name your module after mine, it would seem like yours is based on mine, while it is not.

          Indeed. This is one reason I believe String-Sprintf is not a good enough name for the module you wrote, because there may be other String-Sprintf-* modules, with different takes on an enhanced sprintf-like functionality. I used *-Sprintf-Named to indicate something on the enhancement I intended the module to have.

          Anyway, now that I know it exists, I'll keep an eye on it, and possibly we can try to s