Acme-StringFormat
view release on metacpan or search on metacpan
Acme::StringFormat - Smart interface to sprintf()
VERSION
This document describes Acme::StringFormat version 0.04
SYNOPSIS
use Acme::StringFormat;
# enable 'sprintf' operator in the scope
say '[%s][%s]' % 'foo' % 'bar'; # => [foo][bar]
DESCRIPTION
I had a desire for a "format operator" of other languages. Take boost
C++ libraly for example:
using namespace boost;
std::cout << format("[%1%][%2]") % "foo" % "bar" << std::endl;
Now this pragmatic module provides Perl with a format operator "%",
which is equivalent to "sprintf".
StringFormat.pm view on Meta::CPAN
=head1 VERSION
This document describes Acme::StringFormat version 0.04
=head1 SYNOPSIS
use Acme::StringFormat;
# enable 'sprintf' operator in the scope
say '[%s][%s]' % 'foo' % 'bar'; # => [foo][bar]
=head1 DESCRIPTION
I had a desire for a "format operator" of other languages.
Take boost C++ libraly for example:
using namespace boost;
std::cout << format("[%1%][%2]") % "foo" % "bar" << std::endl;
example/compile_bench.pl view on Meta::CPAN
use 5.010;
use strict;
use warnings;
no warnings 'void';
use Benchmark qw(:all);
use Acme::StringFormat ();
say 'Acme::StringFormat/', Acme::StringFormat->VERSION, "\n";
my $src = join ";\n", (q{ 42 % 2 }) x 100;
cmpthese timethese -1 => {
no__A_SF => sub{
eval q{ no Acme::StringFormat; } . $src;
},
use_A_SF => sub{
eval q{ use Acme::StringFormat; } . $src;
},
example/hello.pl view on Meta::CPAN
#!perl
use 5.010;
use strict;
use warnings;
use Acme::StringFormat;
say '[%s, %s!]' % 'Hello' % 'world';
example/math.pl view on Meta::CPAN
#!perl
use 5.010;
use strict;
use warnings;
use Acme::StringFormat;
for my $n(1 .. 100){
say 'sqrt(%3d) = %5.02f %s' % $n % sqrt($n) % ('*' x (sqrt $n));
}
example/run_bench.pl view on Meta::CPAN
#!perl
use 5.010;
use strict;
use warnings;
use Benchmark qw(:all);
use Acme::StringFormat ();
say 'Acme::StringFromat/', Acme::StringFormat->VERSION, "\n";
my $fmt1 = '[%s]';
my $fmt2 = '[%s][%d]';
my $arg1 = 'foo';
my $arg2 = 10;
say 'number of arguments: 1';
cmpthese timethese -1 => {
'sprintf' => sub{
my $s = sprintf $fmt1, $arg1;
},
'%' => sub{
use Acme::StringFormat;
my $s = $fmt1 % $arg1;
},
};
say 'number of arguments: 2';
cmpthese timethese -1 => {
'sprintf' => sub{
my $s = sprintf $fmt2, $arg1, $arg2;
},
'%' => sub{
use Acme::StringFormat;
my $s = $fmt2 % $arg1 % $arg2;
},
};
( run in 0.622 second using v1.01-cache-2.11-cpan-483215c6ad5 )