Skip to content

Commit da36e4f

Browse files
committed
Some more P5 to P6 hints
- got to pos
1 parent 9dfce10 commit da36e4f

File tree

1 file changed

+103
-21
lines changed

1 file changed

+103
-21
lines changed

doc/Language/5to6-perlfunc.pod6

Lines changed: 103 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,9 @@ in C<$x> containing "howdy".
248248
Note that C<chomp()> (without arguments) is not supported in Perl 6.
249249
250250
The Perl 6 ecosystem has a module C<P5chomp> which exports a C<chomp>
251-
function that mimics the original Perl 5 behaviour as much as possible,
251+
function that mimics the original Perl 5 behaviour as much as possible.
252252
253-
=head2 chop
253+
.head2 chop
254254
255255
=item chop VARIABLE
256256
@@ -261,9 +261,9 @@ being "howdy" and C<$y> being "howd". Also works as a method: C<$y = $x.chop>.
261261
Note that C<chop()> (without arguments) is not supported in Perl 6.
262262
263263
The Perl 6 ecosystem has a module C<P5chomp> which exports a C<chop>
264-
function that mimics the original Perl 5 behaviour as much as possible,
264+
function that mimics the original Perl 5 behaviour as much as possible.
265265
266-
=head2 chown
266+
.head2 chown
267267
268268
=item chown LIST
269269
@@ -283,7 +283,7 @@ function and a method:
283283
Note that C<chr()> (without arguments) is not supported in Perl 6.
284284
285285
The Perl 6 ecosystem has a module C<P5chr> which exports a C<chr>
286-
function that mimics the original Perl 5 behaviour as much as possible,
286+
function that mimics the original Perl 5 behaviour as much as possible.
287287
288288
=head2 chroot
289289
@@ -363,7 +363,7 @@ considered undefined.
363363
Note that C<defined()> (without arguments) is not supported in Perl 6.
364364
365365
The Perl 6 ecosystem has a module C<P5defined> which exports a C<defined>
366-
function that mimics the original Perl 5 behaviour as much as possible,
366+
function that mimics the original Perl 5 behaviour as much as possible.
367367
368368
=head2 delete
369369
@@ -419,7 +419,7 @@ L<https://design.perl6.org/S06.html#%22Pointy_blocks%22>. There is also
419419
some information at L<https://en.wikibooks.org/wiki/Perl_6_Programming/Blocks_and_Closures#Pointy_Blocks>
420420
421421
The Perl 6 ecosystem has a module C<P5each> which exports an C<each>
422-
function that mimics the original Perl 5 behaviour as much as possible,
422+
function that mimics the original Perl 5 behaviour as much as possible.
423423
424424
=head2 eof
425425
@@ -434,7 +434,8 @@ C<$filehandle.eof>. Returns C<True> if at end of file.
434434
435435
=item eval EXPR
436436
437-
Replaced by L<EVAL|/routine/EVAL>. Note that C<EVAL> does not do any L<exception handling|/language/exceptions>!
437+
Replaced by L<EVAL|/routine/EVAL>. Note that C<EVAL> does not do any
438+
L<exception handling|/language/exceptions>!
438439
439440
=head2 evalbytes
440441
@@ -492,7 +493,11 @@ Same as in Perl 5, but can also be used as a method: C<5.exp>;
492493
493494
=item fc EXPR
494495
495-
Looks like it does the same thing as in Perl 5.
496+
Looks like it does the same thing as in Perl 5 except that calling it without
497+
arguments is not supported in Perl 6.
498+
499+
The Perl 6 ecosystem has a module C<P5fc> which exports a C<fc>
500+
function that mimics the original Perl 5 behaviour as much as possible.
496501
497502
=head2 fcntl
498503
@@ -510,8 +515,11 @@ Replaced by C<$?FILE>.
510515
511516
=item fileno FILEHANDLE
512517
513-
S32 indicates that this should be available as a method, but appears currently
514-
unimplemented.
518+
The C<native-descriptor> method on C<IO::Handle> returns the equivalent of
519+
C<fileno>.
520+
521+
The Perl 6 ecosystem has a module C<P5fileno> which exports a C<fileno>
522+
function that mimics the original Perl 5 behaviour as much as possible.
515523
516524
=head2 flock
517525
@@ -673,7 +681,10 @@ C<DateTime> object for the current time, for instance, use C<my $gmtime
673681
674682
=item goto &NAME
675683
676-
goto is not yet implemented
684+
The syntax for C<goto LABEL> is already accepted, but the runtime part of
685+
C<goto> is not yet implemented. So this will result in a runtime error:
686+
687+
FOO: goto FOO; # Label.goto() not yet implemented. Sorry.
677688
678689
=head2 grep
679690
@@ -689,6 +700,8 @@ also be used as a method: C<@foo = @bar.grep(/^f/)>
689700
690701
=item hex EXPR
691702
703+
In Perl 6 an expression B<must> be specified.
704+
692705
Replaced by the adverbial form C<:16>. E. g. C<:16("aF")> returns 175.
693706
694707
Alternately, the same result can be achieved by using the C<.base> method:
@@ -698,6 +711,9 @@ It just so happens that C<.Str> defaults to base 10, so if you just C<say
698711
0xaF>, that will also print 175, but that may not be immediately obvious, so
699712
may not be the best way to go for this.
700713
714+
The Perl 6 ecosystem has a module C<P5hex> which exports a C<hex>
715+
function that mimics the original Perl 5 behaviour as much as possible.
716+
701717
=head2 import
702718
703719
=item import LIST
@@ -713,7 +729,19 @@ L<this section|/language/5to6-nutshell#Importing_specific_functions_from_a_modul
713729
=item index STR, SUBSTR, POSITION
714730
715731
Works as in Perl 5. Can also now be used as a method:
716-
C<"howdy!".index("how"); # 0>
732+
C<"howdy!".index("how"); # 0>. Main difference with Perl 5 is that C<Nil> is
733+
returned instead of C<-1>. This is very useful in combination with the
734+
C<with> command:
735+
736+
with index("foo","o") -> $index {
737+
say "Found it at $index";
738+
}
739+
else {
740+
say "Not found"
741+
}
742+
743+
The Perl 6 ecosystem has a module C<P5index> which exports an C<index>
744+
function that mimics the original Perl 5 behaviour as much as possible.
717745
718746
=head2 int
719747
@@ -725,6 +753,14 @@ translation of Perl 5 code, but in Perl 6, you can just as easily call
725753
the C<.Int> method on the number. C<3.9.Int; # 3> and C<3.9.truncate>
726754
are equivalent.
727755
756+
Please note that C<int> B<does> have a meaning in Perl 6. It is type that
757+
can be used to indicate a native integer:
758+
759+
my int $a = 42; # a native integer, similar to Perl 5's integer values
760+
761+
Because of this, it has proven impossible to create a Perl 6 module that
762+
would export a sub that would mimic the Perl 5 behaviour.
763+
728764
=head2 ioctl
729765
730766
=item ioctl FILEHANDLE, FUNCTION, SCALAR
@@ -773,21 +809,31 @@ Same as in Perl 5.
773809
774810
=item lc EXPR
775811
776-
Works as in Perl 5, and also as a method: C<"UGH".lc>
812+
Works as in Perl 5, and also as a method: C<"UGH".lc>. In Perl 6 an
813+
expression B<must> be specified.
814+
815+
The Perl 6 ecosystem has a module C<P5lc> which exports an C<lc>
816+
function that mimics the original Perl 5 behaviour as much as possible.
777817
778818
=head2 lcfirst
779819
780820
=item lcfirst EXPR
781821
782822
Does not exist in Perl 6.
783823
824+
The Perl 6 ecosystem has a module C<P5lcfirst> which exports an C<lcfirst>
825+
function that mimics the original Perl 5 behaviour as much as possible.
826+
784827
=head2 length
785828
786829
=item length EXPR
787830
788831
Replaced by C<chars>, typically used as a method (C<$string.chars>), but
789832
also works as a function.
790833
834+
The Perl 6 ecosystem has a module C<P5length> which exports an C<length>
835+
function that mimics the original Perl 5 behaviour as much as possible.
836+
791837
=head2 __LINE__
792838
793839
=item __LINE__
@@ -847,14 +893,16 @@ lines of "2015-06-29T12:49:31-04:00".
847893
848894
=item lock THING
849895
850-
In Perl 6, a method in the C<Lock> class.
896+
There currently is no equivalent for this In Perl 6. There is a C<Lock>
897+
class for creating a Lock object, that can be locked/unlocked as needed.
898+
But such a lock does not refer to any external objects.
851899
852900
=head2 log
853901
854902
=item log EXPR
855903
856-
Available in Perl 6. Also works as a method. I. e. C<log(2)> is
857-
equivalent to C<2.log>.
904+
Available in Perl 6, but B<must> have an expression to work on. Also available
905+
as a method. I. e. C<log(2)> is equivalent to C<2.log>.
858906
859907
=head2 lstat
860908
@@ -896,7 +944,10 @@ used as a method: C<@new = @old.map: { $_ * 2 }>
896944
897945
=item mkdir FILENAME
898946
899-
Works as in Perl 5.
947+
Works as in Perl 5. When giving a multi-level directory specification,
948+
it will automatically create non-existing intermediate directories with
949+
the same MASK (similar to what "make_path" does of the File::Path module
950+
in Perl 5).
900951
901952
=item mkdir
902953
@@ -958,6 +1009,9 @@ Replaced by the adverbial form C<:8>. E. g. C<:8("100")> returns 64.
9581009
If you want to deal with strings that start in C<0x>, C<0o>, or C<0b>,
9591010
you can just use the C«prefix:<+>» operator.
9601011
1012+
The Perl 6 ecosystem has a module C<P5hex> which exports an C<oct>
1013+
function that mimics the original Perl 5 behaviour as much as possible.
1014+
9611015
=head2 open
9621016
9631017
=item open FILEHANDLE, EXPR
@@ -990,6 +1044,11 @@ No replacement. See L«C<&dir>/C<IO::Path.dir>|/routine/dir» for alternatives.
9901044
9911045
Same as in Perl 5. May be used as a method: C<"howdy!".ord; # 104>
9921046
1047+
Note that C<ord()> (without arguments) is not supported in Perl 6.
1048+
1049+
The Perl 6 ecosystem has a module C<P5chr> which exports a C<ord>
1050+
function that mimics the original Perl 5 behaviour as much as possible.
1051+
9931052
=head2 our
9941053
9951054
=item our VARLIST
@@ -1006,9 +1065,15 @@ The same in Perl 6.
10061065
10071066
=item pack TEMPLATE, LIST
10081067
1009-
Available in Perl 6. The template options are currently more restricted
1010-
than they are in Perl 5. The current documented list can be found at
1011-
L<unpack|/routine/unpack>.
1068+
Available in Perl 6 when C<use experimental :pack> has been specified in the
1069+
scope where C<pack> needs to be called. The template options are currently
1070+
more restricted than they are in Perl 5. The current documented list can be
1071+
found at L<unpack|/routine/unpack>.
1072+
1073+
The Perl 6 ecosystem has a module C<P5pack> which exports a C<pack>
1074+
function that mimics the original Perl 5 behaviour as much as possible
1075+
and which has a bigger set of supported features than the experimental
1076+
Perl 6 version.
10121077
10131078
=head2 package
10141079
@@ -1051,6 +1116,23 @@ and from processes.
10511116
Works in Perl 6, and can also be used as a method. I. e. C<my $x = pop
10521117
@a;> and C<my $x = @a.pop;> are equivalent.
10531118
1119+
The non-paramater version of C<pop> does not exist. Also, if the array
1120+
is empty, a Failure will be returned in Perl 6, which will throw if the
1121+
value is actually used in a significant way.
1122+
1123+
If you are using only defined values in your array, you can use the C<with>
1124+
function to handle this case:
1125+
1126+
with pop @array -> $popped {
1127+
say "popped '$popped' of the array";
1128+
}
1129+
else {
1130+
say "there was nothing to pop";
1131+
}
1132+
1133+
The Perl 6 ecosystem has a module C<P5push> which exports a C<pop>
1134+
function that mimics the original Perl 5 behaviour as much as possible
1135+
10541136
=head2 pos
10551137
10561138
=item pos SCALAR

0 commit comments

Comments
 (0)