Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > cd14cddf3b3ceaf1193157472227757a > files > 895

parrot-doc-1.6.0-1mdv2010.0.i586.rpm

# Copyright (C) 2007-2009, Parrot Foundation.
# $Id: 32_array_ops_sprintf.pir 39674 2009-06-20 14:09:03Z cotto $

=head1

C<sprintf> is a function common to most programmers as part of the C
standard library that allows the creation of a string from a given
format and a list of operators. Parrot's C<sprintf> operator extends
the format options of the regular sprintf function, and allows
arguments to be taken from inside an array PMC.

=cut

.sub main :main

    .local pmc myarray
    myarray = new ['ResizablePMCArray']

    $P0 = new ['Integer']
    $P0 = 42
    push myarray, $P0

    $P1 = new ['Float']
    $P1 = 10.5
    push myarray, $P1

    $S0 = sprintf "int %#Px num %+2.2Pf\n", myarray
    print $S0     # prints "int 0x2a num +10.50"
    print "\n"

.end

# Local Variables:
#   mode: pir
#   fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: