[PDD] Add docs for the Parrot_PMC_push_* and Parrot_PMC_pop_* functions
[parrot.git] / examples / tutorial / 32_array_ops_sprintf.pir
blobf0c8dfb57cbd157061c1207497bb586c42c1ce76
1 # Copyright (C) 2007-2009, Parrot Foundation.
2 # $Id$
4 =head1
6 C<sprintf> is a function common to most programmers as part of the C
7 standard library that allows the creation of a string from a given
8 format and a list of operators. Parrot's C<sprintf> operator extends
9 the format options of the regular sprintf function, and allows
10 arguments to be taken from inside an array PMC.
12 =cut
14 .sub main :main
16     .local pmc myarray
17     myarray = new ['ResizablePMCArray']
19     $P0 = new ['Integer']
20     $P0 = 42
21     push myarray, $P0
23     $P1 = new ['Float']
24     $P1 = 10.5
25     push myarray, $P1
27     $S0 = sprintf "int %#Px num %+2.2Pf\n", myarray
28     print $S0     # prints "int 0x2a num +10.50"
29     print "\n"
31 .end
33 # Local Variables:
34 #   mode: pir
35 #   fill-column: 100
36 # End:
37 # vim: expandtab shiftwidth=4 ft=pir: