4 | 4 |
# o. Lars D implemented a times() method for scalars but there is no doc or comment and I don't see the point; commented it out for now.
|
5 | 5 |
# (scrottie)
|
6 | 6 |
# o. @array->random ?
|
7 | |
# o. "5->times(sub { print "hi\n"}); # XXX likely to change but it's in the code so bloody doc it so I have incentive to rethink it".
|
|
7 |
# o. "5->times(sub { print "hi\n"}); # XXX likely to change but it's in the code so bloody doc it so I have incentive to rethink it".
|
8 | 8 |
# well? do we want this? (scrottie)
|
9 | 9 |
# o. kill head() and tail() -- does it really make sense to try to emulate linked lists with Perl arrays? cute idea, but, uh. (scrottie)
|
10 | 10 |
# o. "There's currently no counterpart to the C<< \ >> operator" -- but should we back away from trying to name operators and
|
|
86 | 86 |
[10, 20, 30, 40, 50]->pop->say;
|
87 | 87 |
[10, 20, 30, 40, 50]->shift->say;
|
88 | 88 |
|
89 | |
my $lala = "Lalalalala\n";
|
|
89 |
my $lala = "Lalalalala\n";
|
90 | 90 |
"chomp: "->concat($lala->chomp, " ", $lala)->say;
|
91 | 91 |
|
92 | 92 |
my $hashref = { foo => 10, bar => 20, baz => 30, qux => 40 };
|
|
132 | 132 |
messy dereferencing syntaxes.
|
133 | 133 |
|
134 | 134 |
F<autobox::Core> is mostly glue. It presents existing functions with a new
|
135 | |
interface, while adding few extra. Most of the methods read like
|
|
135 |
interface, while adding few extra. Most of the methods read like
|
136 | 136 |
C<< sub hex { CORE::hex($_[0]) } >>. In addition to built-ins from
|
137 | 137 |
L<perlfunc> that operate on hashes, arrays, scalars, and code references,
|
138 | 138 |
some Perl 6-ish things have been included, and some keywords like
|
|
204 | 204 |
context), L<rindex|perlfunc/rindex>,
|
205 | 205 |
L<sprintf|perlfunc/sprintf>, L<substr|perlfunc/substr>, L<uc|perlfunc/uc>
|
206 | 206 |
L<ucfirst|perlfunc/ucfirst>, L<unpack|perlfunc/unpack>, L<quotemeta|perlfunc/quotemeta>,
|
207 | |
L<vec|perlfunc/vec>, L<undef|perlfunc/undef>,
|
|
207 |
L<vec|perlfunc/vec>, L<undef|perlfunc/undef>,
|
208 | 208 |
L<split|perlfunc/split>, L<system|perlfunc/system>, L<eval|perlfunc/eval>.
|
209 | 209 |
|
210 | 210 |
In addition, so are each of the following:
|
|
213 | 213 |
|
214 | 214 |
$string1->concat($string2);
|
215 | 215 |
|
216 | |
Concatenates C<$string2> to C<$string1>. This
|
|
216 |
Concatenates C<$string2> to C<$string1>. This
|
217 | 217 |
corresponds to the C<.> operator used to join two strings. Returns the
|
218 | 218 |
joined strings.
|
219 | 219 |
|
|
233 | 233 |
string.
|
234 | 234 |
|
235 | 235 |
' hello'->trim; # 'hello'
|
236 | |
'*+* hello *+*'->trim("*+"); # ' hello '
|
|
236 |
'*+* hello *+*'->trim("*+"); # ' hello '
|
237 | 237 |
' *+* hello *+*'->trim("*+"); # ' *+* hello'
|
238 | 238 |
|
239 | 239 |
=head4 ltrim
|
|
286 | 286 |
C<center()> will never truncate C<$string>. If $length is less
|
287 | 287 |
than C<< $string->length >> it will just return C<$string>.
|
288 | 288 |
|
289 | |
say "Hello"->center(4); # "Hello";
|
|
289 |
say "Hello"->center(4); # "Hello";
|
290 | 290 |
|
291 | 291 |
=head4 qx
|
292 | 292 |
|
|
329 | 329 |
my $string = "the cat sat on the mat";
|
330 | 330 |
$string->s( qr/cat/, "dog" );
|
331 | 331 |
$string->say; # the dog sat on the mat
|
332 | |
|
333 | |
String substitution. Works similarly to C<< s/// >>.
|
|
332 |
|
|
333 |
String substitution. Works similarly to C<< s/// >>.
|
334 | 334 |
In boolean context, it returns true/false to indicate whether the substitution succeeded. C<if>, C<?:>, C<!>, and so on, all provide boolean context.
|
335 | 335 |
It either fails or succeeds, having replaced only one occurance on success -- it doesn't replace globally.
|
336 | 336 |
In scalar context other than boolean context, it returns the modified string (incompatible change, new as of v 1.31).
|
|
368 | 368 |
|
369 | 369 |
$string->print;
|
370 | 370 |
|
371 | |
Prints a string or a list of strings. Returns true if successful.
|
|
371 |
Prints a string or a list of strings. Returns true if successful.
|
372 | 372 |
|
373 | 373 |
=head4 say
|
374 | 374 |
|
|
382 | 382 |
|
383 | 383 |
=head4 and
|
384 | 384 |
|
385 | |
C<and> corresponds to C<&&>. Returns true if both operands are true.
|
|
385 |
C<and> corresponds to C<&&>. Returns true if both operands are true.
|
386 | 386 |
|
387 | 387 |
if( $a->and($b) ) {
|
388 | 388 |
...
|
|
541 | 541 |
L<bless|perlfunc/bless>, L<tie|perlfunc/tie>, L<tied|perlfunc/tied>,
|
542 | 542 |
L<ref|perlfunc/ref>, L<grep|perlfunc/grep>, L<map|perlfunc/map>,
|
543 | 543 |
L<join|perlfunc/join>, L<reverse|perlfunc/reverse>, and
|
544 | |
L<sort|perlfunc/sort>, L<each|perlfunc/each>.
|
|
544 |
L<sort|perlfunc/sort>, L<each|perlfunc/each>.
|
545 | 545 |
|
546 | 546 |
As well as:
|
547 | 547 |
|
|
555 | 555 |
|
556 | 556 |
=head4 uniq
|
557 | 557 |
|
558 | |
Removes all duplicate elements from an array and returns the new array
|
|
558 |
Removes all duplicate elements from an array and returns the new array
|
559 | 559 |
with no duplicates.
|
560 | 560 |
|
561 | 561 |
my @array = qw( 1 1 2 3 3 6 6 );
|
|
690 | 690 |
|
691 | 691 |
=head4 tail
|
692 | 692 |
|
693 | |
Returns all but the first element from C<@list>.
|
|
693 |
Returns all but the first element from C<@list>.
|
694 | 694 |
|
695 | 695 |
my @list = qw(foo bar baz quux);
|
696 | 696 |
my @rest = @list->tail; # [ 'bar', 'baz', 'quux' ]
|
|
806 | 806 |
print $_[0], ' is ', $hash{$_[0]}, "\n";
|
807 | 807 |
});
|
808 | 808 |
|
809 | |
=head4 lock_keys
|
|
809 |
=head4 lock_keys
|
810 | 810 |
|
811 | 811 |
%hash->lock_keys;
|
812 | 812 |
|
|
854 | 854 |
Methods which work on code references.
|
855 | 855 |
|
856 | 856 |
These are simple wrappers around the Perl core functions.
|
857 | |
L<bless|perlfunc/bless>, L<ref|perlfunc/ref>,
|
|
857 |
L<bless|perlfunc/bless>, L<ref|perlfunc/ref>,
|
858 | 858 |
|
859 | 859 |
Due to Perl's precedence rules, some autoboxed literals may need to be
|
860 | 860 |
parenthesized. For instance, this works:
|
|
891 | 891 |
|
892 | 892 |
=over 4
|
893 | 893 |
|
894 | |
=item *
|
|
894 |
=item *
|
895 | 895 |
|
896 | 896 |
File and socket operations are already implemented in an object-oriented
|
897 | 897 |
fashion care of L<IO::Handle>, L<IO::Socket::INET>, and L<IO::Any>.
|
898 | 898 |
|
899 | 899 |
=item *
|
900 | 900 |
|
901 | |
Functions listed in the L<perlfunc> headings
|
|
901 |
Functions listed in the L<perlfunc> headings
|
902 | 902 |
|
903 | 903 |
=over 4
|
904 | 904 |
|
|
946 | 946 |
|
947 | 947 |
=item *
|
948 | 948 |
|
949 | |
(Most) binary operators
|
|
949 |
(Most) binary operators
|
950 | 950 |
|
951 | 951 |
=back
|
952 | 952 |
|
|
994 | 994 |
This is a more Perl 6 way of doing things.
|
995 | 995 |
|
996 | 996 |
# Perl 6 - autoboxing associates classes with primitives types:
|
997 | |
|
|
997 |
|
998 | 998 |
print 4.sqrt, "\n";
|
999 | 999 |
|
1000 | 1000 |
print [ 1 .. 20 ].elems, "\n";
|
|
1304 | 1304 |
sub m { my @ms = $_[0] =~ m{$_[1]} ; return @ms ? \@ms : undef }
|
1305 | 1305 |
sub nm { my @ms = $_[0] =~ m{$_[1]} ; return @ms ? undef : \@ms }
|
1306 | 1306 |
sub split { wantarray ? split $_[1], $_[0] : [ split $_[1], $_[0] ] }
|
1307 | |
sub s {
|
1308 | |
my $success = ( $_[0] =~ s{$_[1]}{$_[2]} ) ? 1 : 0;
|
|
1307 |
sub s {
|
|
1308 |
my $success = ( $_[0] =~ s{$_[1]}{$_[2]} ) ? 1 : 0;
|
1309 | 1309 |
if (Want::want('LIST')) {
|
1310 | 1310 |
Want::rreturn ($_[0]);
|
1311 | 1311 |
} elsif (Want::want('BOOL')) { # this needs to happen before the SCALAR context test
|