Skip to content

Commit

Permalink
Some more Perl 5 -> 6 tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Apr 28, 2018
1 parent b8c697d commit d779c58
Showing 1 changed file with 71 additions and 23 deletions.
94 changes: 71 additions & 23 deletions doc/Language/5to6-perlfunc.pod6
Expand Up @@ -1370,7 +1370,7 @@ C<with> command:
say "Not found"
}
The Perl 6 ecosystem has a module C<P5index> which exports an C<rindex>
The Perl 6 ecosystem has a module C<P5index> which exports a C<rindex>
function that mimics the original Perl 5 behaviour as much as possible.
=head2 rmdir
Expand Down Expand Up @@ -1527,6 +1527,17 @@ equivalent.
Still works as in Perl 5, but is not limited to integer values for seconds.
And it always returns Nil.
If you're interested in the return values of C<sleep> to ensure sleeping until
a specified time, then you should use C<sleep-until> in Perl 6 (which takes
an C<Instant>).
If you're interested in running some code every N seconds, and you don't care
on which thread it runs, you should probably use C<react> and C<whenever>
with a C<Supply.interval>.
The Perl 6 ecosystem has a module C<P5sleep> which exports a C<sleep>
function that mimics the original Perl 5 behaviour as much as possible.
=head2 sockets
=item socket SOCKET, DOMAIN, TYPE, PROTOCOL
Expand Down Expand Up @@ -1573,7 +1584,6 @@ Available in Perl 6. Can also be used as a method. C<< splice(@foo, 2, 3,
=item split /PATTERN/
Works mostly as in Perl 5. There are some exceptions, though. To get the
special behavior of using the empty string, you must actually use the
empty string - the special case of the empty pattern C<//> being treated
Expand Down Expand Up @@ -1680,6 +1690,9 @@ Available in Perl 6, see L<state|/syntax/state>.
C<study> is no more.
The Perl 6 ecosystem has a module C<P5study> which exports a C<study>
function that mimics the original Perl 5 behaviour as much as possible.
=head2 sub
=item sub NAME BLOCK
Expand Down Expand Up @@ -1720,7 +1733,7 @@ C<"hola!".substr(1, 3)> both return "ola".
=item symlink OLDFILE, NEWFILE
See L<symlink>
See L<symlink>.
=head2 syscall
Expand Down Expand Up @@ -1767,7 +1780,7 @@ As with C<sysopen> and friends, this has moved into the C<IO> classes.
=item tell FILEHANDLE
In C<IO::Handle>, but not yet documented, beyond a mention.
As a method on C<IO::Handle>.
=head2 telldir
Expand All @@ -1781,24 +1794,41 @@ Possibly in C<IO::Path>, but not yet documented.
=item tied VARIABLE
[NEEDS FURTHER RESEARCH] S29 indicates that variable tying has been
replaced by container types. Unfortunately, what this means in practical
terms has not been obviously specified.
The Perl 6 alternative to tieing a scalar, is the C<Proxy> container. For
example:
sub lval() { Proxy.new(
FETCH => method () { ...},
STORE => method ($new) { ... }
) }
This makes C<lval> a left-value sub. Whenever the value is requested, the
C<FETCH> method is called. And whenever it is used in an assignment, the
C<STORE> method is called.
For arrays and hashes (objects that do the C<Positional> and/or C<Associative>
role), one only needs to provide the methods that these roles require to get
the functionality that C<tie> provides in Perl 5. These are documented in
the C<Subscripts> section.
The Perl 6 ecosystem has a module C<P5tie> which exports C<tie> / C<tied>
functions that mimics the original Perl 5 behaviour as much as possible.
=head2 time
=item time
"Returns an Int representing the current time." Although I<how> it represents the
current time isn't in the documentation currently, it appears to still be
seconds since epoch, as in Perl 5.
Number of seconds since epoch (as an C<Int>), same as in Perl 5.
=head2 times
=item times
Not available in Perl 6.
The Perl 6 ecosystem has a module C<P5times> which exports a C<times>
function that mimics the original Perl 5 behaviour as much as possible.
=head2 tr///
=item tr///
Expand All @@ -1817,29 +1847,37 @@ The C<y///> equivalent does not exist.
=item truncate EXPR, LENGTH
Most likely somewhere in C<IO::Handle>, but not currently documented.
Not currently implemented (2018.04).
=head2 uc
=item uc EXPR
Works as a function and a method. C<uc("ha")> and C<"ha".uc> both return "HA".
There is no support for the parameterless version.
The Perl 6 ecosystem has a module C<P5lc> which exports a C<uc>
function that mimics the original Perl 5 behaviour as much as possible.
=head2 ucfirst
=item ucfirst EXPR
=item ucfirst
Perl 6 has done away with C<ucfirst>. The title case function L<C<tc>|/routine/tc> probably
does what you need.
Perl 6 has done away with C<ucfirst>. The title case function
L<C<tc>|/routine/tc> probably does what you need.
The Perl 6 ecosystem has a module C<P5lcfirst> which exports a C<ucfirst>
function that mimics the original Perl 5 behaviour as much as possible.
=head2 undef
=item undef EXPR
There is no C<undef> in Perl 6. You can't undefine a function, and the closest
equivalent value is probably C<Nil>, but you'll likely have no use for that.
If you were using something like C<(undef, $file, $line) = caller;>, you would
just get the filename and line number directly in Perl 6 instead of discarding
the first result of C<caller>. C<caller> has been replaced by C<callframe> in
Expand All @@ -1865,10 +1903,15 @@ The zero argument (implicit C<$_>) version of unlink is not available in Perl 6
=item unpack TEMPLATE
Available in Perl 6. The template options are currently more restricted
than they are in Perl 5. The current documented list can be found
L<here|/routine/unpack>.
Available in Perl 6 when C<use experimental :pack> has been specified in the
scope where C<unpack> needs to be called. The template options are currently
more restricted than they are in Perl 5. The current documented list can be
found at L<unpack|/routine/unpack>.
The Perl 6 ecosystem has a module C<P5pack> which exports a C<unpack>
function that mimics the original Perl 5 behaviour as much as possible
and which has a bigger set of supported features than the experimental
Perl 6 version.
=head2 unshift
Expand All @@ -1883,9 +1926,10 @@ equivalent to C<@a.unshift("blah")>.
=item untie VARIABLE
[NEEDS FURTHER RESEARCH] Functions for tying variables seem to be replaced in
Perl 6 by container types, as mentioned in S29. This has become no clearer
since I wrote the entry for C<tie>, above.
Not supported in Perl 6, but see L<tie> for the whole story.
The Perl 6 ecosystem has a module C<P5tie> which exports a C<untie>
function that mimics the original Perl 5 behaviour as much as possible.
=head2 use
Expand Down Expand Up @@ -1920,14 +1964,18 @@ No equivalent.
Available in Perl 6. Can also be used as a method. C<values %hash> is
equivalent to C<%hash.values>.
=head2 vec
=item vec EXPR, OFFSET, BITS
There is no support for vec() in Perl 6.
S29 says "Should replace C<vec> with declared buffer/array of C<bit>,
C<uint2>, C<uint4>, etc." It is unclear, however, that this has actually
happened.
C<uint2>, C<uint4>, etc." Support for C<bit>, C<uint2>, C<uint4> has not
landed yet. But support for C<uint8>, C<int8>, C<uint16>, C<int16>,
C<uint32>, C<int32>, C<uint64>, C<int64> as well as the system sized
C<uint> and C<int> B<have> landed. In scalar forms, as well as in array
and shaped array (aka matrix) forms.
=head2 wait
Expand Down Expand Up @@ -2021,7 +2069,7 @@ not advised:
=item warn LIST
C<warn> throws an exception. To simply print a message to C<$*ERR>, you
C<warn> throws a resumable exception. To simply print a message to C<$*ERR>, you
would use the C<note> function. For more on exceptions, see
L<Exceptions|/language/exceptions>.
Expand Down

0 comments on commit d779c58

Please sign in to comment.