The printf()
example in the docs doesn't work for me:
~/p6_programs$ perl6 -v This is Rakudo version 2016.11 built on MoarVM version 2016.11 implementing Perl 6.c. ~/p6_programs$ cat 4.pl6 my $fh = open 'outfile.txt', :w; $fh.printf: "The value is %d\n", 32; $fh.close; ~/p6_programs$ perl6 4.pl6 No such method 'printf' for invocant of type 'IO::Handle' in block <unit> at 4.pl6 line 3
You can use sprintf()
as a workaround:
my $fh = open 'outfile.txt', :w; $fh.say: sprintf "The value is %d", 32; $fh.close;
or fmt()
:
my $fh = open 'outfile.txt', :w; $fh.say: 32.fmt("The value is %d"); $fh.close;
source share