tokuhirom's Blog

Text::Xslate で commify とかしたいときのやりかた

use 5.12.0;
use Text::Xslate;

my $xslate = Text::Xslate->new(
    module => ['Number::Format' => [':subs']],
    syntax => 'TTerse',
);
say $xslate->render_string('[% 100000000 | format_number %]');

こうかな。

あるいは

my $xslate = Text::Xslate->new(
    function => {
        commify => sub {
            local $_ = shift;
            1 while s/^([-+]?\d+)(\d\d\d)/$1,$2/;
            $_;
        },
    },
    syntax => 'TTerse',
);
say $xslate->render_string('[% 100000000 | commify %]');

かな。