Skip to content

Commit 5de332b

Browse files
committed
merge
2 parents a7976f1 + a4bf58e commit 5de332b

File tree

2 files changed

+108
-1
lines changed

2 files changed

+108
-1
lines changed

doc/Type/Array.pod

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ The difference to method C<push> is that with an array or list argument,
9999
C<append> appends several elements (one for each array or list element),
100100
whereas C<push> appends just one element.
101101
102+
Example:
103+
104+
my @a = <a b c>;
105+
my @b = <d e f>;
106+
@a.append: @b;
107+
say @a.elems; # 6
108+
say @a; # a b c d e f
109+
102110
=head2 routine shift
103111
104112
Defined as:
@@ -140,7 +148,7 @@ Example:
140148
141149
my @foo = <a b c>;
142150
@foo.unshift: 1, 3 ... 11;
143-
say @foo; # 1 3 5 7 9 11 a b c
151+
say @foo; # (1 3 5 7 9 11) a b c
144152
145153
The notes in L<the documentation for method push|#method push> apply,
146154
regarding how many elements are added to the array.
@@ -164,6 +172,12 @@ Usage:
164172
Adds the elements from C<LIST> to the front of the array, modifying it
165173
in-place.
166174
175+
Example:
176+
177+
my @foo = <a b c>;
178+
@foo.prepend: 1, 3 ... 11;
179+
say @foo; # 1 3 5 7 9 11 a b c
180+
167181
=head2 routine splice
168182
169183
Defined as:

doc/Type/Str.pod

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,99 @@ Examples:
344344
"Perl".flip; # lreP
345345
"ABBA".flip; # ABBA
346346
347+
=head2 sub printf
348+
349+
multi sub printf (Str:D $format, *@args)
350+
351+
This function is mostly identical to the C library printf function.
352+
353+
The C<$format> is scanned for C<%> characters. Any C<%> introduces a
354+
format token. Format tokens have the following grammar:
355+
356+
grammar Str::PrintfFormat {
357+
regex format_token { '%': <index>? <precision>? <modifier>? <directive> }
358+
token index { \d+ '$' }
359+
token precision { <flags>? <vector>? <precision_count> }
360+
token flags { <[ \x20 + 0 \# \- ]>+ }
361+
token precision_count { [ <[1..9]>\d* | '*' ]? [ '.' [ \d* | '*' ] ]? }
362+
token vector { '*'? v }
363+
token modifier { < ll l h V q L > }
364+
token directive { < % c s d u o x e f g X E G b p n i D U O F > }
365+
}
366+
367+
Directives guide the use (if any) of the arguments. When a directive
368+
(other than C<%>) is used, it indicates how the next argument
369+
passed is to be formatted into the string to be printed.
370+
371+
The directives are:
372+
373+
=begin table
374+
375+
% a literal percent sign
376+
c a character with the given codepoint
377+
s a string
378+
d a signed integer, in decimal
379+
u an unsigned integer, in decimal
380+
o an unsigned integer, in octal
381+
x an unsigned integer, in hexadecimal
382+
e a floating-point number, in scientific notation
383+
f a floating-point number, in fixed decimal notation
384+
g a floating-point number, in %e or %f notation
385+
X like x, but using uppercase letters
386+
E like e, but using an uppercase "E"
387+
G like g, but with an uppercase "E" (if applicable)
388+
b an unsigned integer, in binary
389+
390+
=end table
391+
392+
Compatibility:
393+
394+
=begin table
395+
396+
i a synonym for %d
397+
D a synonym for %ld
398+
U a synonym for %lu
399+
O a synonym for %lo
400+
F a synonym for %f
401+
402+
=end table
403+
404+
Perl 5 (non-)compatibility:
405+
406+
=begin table
407+
408+
n produces a runtime exception
409+
p produces a runtime exception
410+
411+
=end table
412+
413+
Modifiers change the meaning of format directives, but are largely
414+
no-ops (the semantics are still being determined).
415+
416+
=begin table
417+
418+
h interpret integer as native "short" (typically int16)
419+
l interpret integer as native "long" (typically int32 or int64)
420+
ll interpret integer as native "long long" (typically int64)
421+
L interpret integer as native "long long" (typically uint64)
422+
q interpret integer as native "quads" (typically int64 or larger)
423+
424+
=end table
425+
426+
Examples:
427+
428+
printf('%c', [97]); # a
429+
printf("%.2f", [1.969]); # 1.97
430+
printf("%+.3f", [3.141592]); # +3.142
431+
printf('%2$d %1$d', [12, 34]); # 34 12
432+
printf("%x", [255]); # ff
433+
434+
Special case: printf("<b>%s</b>\n", "Perl 6") will not work use either of the following:
435+
436+
printf Q:b "<b>%s</b>\n", "Perl 6";
437+
printf "<b>\%s</b>\n", "Perl 6";
438+
printf "<b>%s\</b>\n", "Perl 6";
439+
347440
=head2 sub sprintf
348441
349442
multi sub sprintf ( Str:D $format, *@args) returns Str:D

0 commit comments

Comments
 (0)