Skip to content

Commit d779c58

Browse files
committed
Some more Perl 5 -> 6 tweaks
1 parent b8c697d commit d779c58

File tree

1 file changed

+71
-23
lines changed

1 file changed

+71
-23
lines changed

doc/Language/5to6-perlfunc.pod6

Lines changed: 71 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,7 +1370,7 @@ C<with> command:
13701370
say "Not found"
13711371
}
13721372
1373-
The Perl 6 ecosystem has a module C<P5index> which exports an C<rindex>
1373+
The Perl 6 ecosystem has a module C<P5index> which exports a C<rindex>
13741374
function that mimics the original Perl 5 behaviour as much as possible.
13751375
13761376
=head2 rmdir
@@ -1527,6 +1527,17 @@ equivalent.
15271527
Still works as in Perl 5, but is not limited to integer values for seconds.
15281528
And it always returns Nil.
15291529
1530+
If you're interested in the return values of C<sleep> to ensure sleeping until
1531+
a specified time, then you should use C<sleep-until> in Perl 6 (which takes
1532+
an C<Instant>).
1533+
1534+
If you're interested in running some code every N seconds, and you don't care
1535+
on which thread it runs, you should probably use C<react> and C<whenever>
1536+
with a C<Supply.interval>.
1537+
1538+
The Perl 6 ecosystem has a module C<P5sleep> which exports a C<sleep>
1539+
function that mimics the original Perl 5 behaviour as much as possible.
1540+
15301541
=head2 sockets
15311542
15321543
=item socket SOCKET, DOMAIN, TYPE, PROTOCOL
@@ -1573,7 +1584,6 @@ Available in Perl 6. Can also be used as a method. C<< splice(@foo, 2, 3,
15731584
15741585
=item split /PATTERN/
15751586
1576-
15771587
Works mostly as in Perl 5. There are some exceptions, though. To get the
15781588
special behavior of using the empty string, you must actually use the
15791589
empty string - the special case of the empty pattern C<//> being treated
@@ -1680,6 +1690,9 @@ Available in Perl 6, see L<state|/syntax/state>.
16801690
16811691
C<study> is no more.
16821692
1693+
The Perl 6 ecosystem has a module C<P5study> which exports a C<study>
1694+
function that mimics the original Perl 5 behaviour as much as possible.
1695+
16831696
=head2 sub
16841697
16851698
=item sub NAME BLOCK
@@ -1720,7 +1733,7 @@ C<"hola!".substr(1, 3)> both return "ola".
17201733
17211734
=item symlink OLDFILE, NEWFILE
17221735
1723-
See L<symlink>
1736+
See L<symlink>.
17241737
17251738
=head2 syscall
17261739
@@ -1767,7 +1780,7 @@ As with C<sysopen> and friends, this has moved into the C<IO> classes.
17671780
17681781
=item tell FILEHANDLE
17691782
1770-
In C<IO::Handle>, but not yet documented, beyond a mention.
1783+
As a method on C<IO::Handle>.
17711784
17721785
=head2 telldir
17731786
@@ -1781,24 +1794,41 @@ Possibly in C<IO::Path>, but not yet documented.
17811794
17821795
=item tied VARIABLE
17831796
1784-
[NEEDS FURTHER RESEARCH] S29 indicates that variable tying has been
1785-
replaced by container types. Unfortunately, what this means in practical
1786-
terms has not been obviously specified.
1797+
The Perl 6 alternative to tieing a scalar, is the C<Proxy> container. For
1798+
example:
1799+
1800+
sub lval() { Proxy.new(
1801+
FETCH => method () { ...},
1802+
STORE => method ($new) { ... }
1803+
) }
1804+
1805+
This makes C<lval> a left-value sub. Whenever the value is requested, the
1806+
C<FETCH> method is called. And whenever it is used in an assignment, the
1807+
C<STORE> method is called.
1808+
1809+
For arrays and hashes (objects that do the C<Positional> and/or C<Associative>
1810+
role), one only needs to provide the methods that these roles require to get
1811+
the functionality that C<tie> provides in Perl 5. These are documented in
1812+
the C<Subscripts> section.
1813+
1814+
The Perl 6 ecosystem has a module C<P5tie> which exports C<tie> / C<tied>
1815+
functions that mimics the original Perl 5 behaviour as much as possible.
17871816
17881817
=head2 time
17891818
17901819
=item time
17911820
1792-
"Returns an Int representing the current time." Although I<how> it represents the
1793-
current time isn't in the documentation currently, it appears to still be
1794-
seconds since epoch, as in Perl 5.
1821+
Number of seconds since epoch (as an C<Int>), same as in Perl 5.
17951822
17961823
=head2 times
17971824
17981825
=item times
17991826
18001827
Not available in Perl 6.
18011828
1829+
The Perl 6 ecosystem has a module C<P5times> which exports a C<times>
1830+
function that mimics the original Perl 5 behaviour as much as possible.
1831+
18021832
=head2 tr///
18031833
18041834
=item tr///
@@ -1817,29 +1847,37 @@ The C<y///> equivalent does not exist.
18171847
18181848
=item truncate EXPR, LENGTH
18191849
1820-
Most likely somewhere in C<IO::Handle>, but not currently documented.
1850+
Not currently implemented (2018.04).
18211851
18221852
=head2 uc
18231853
18241854
=item uc EXPR
18251855
18261856
Works as a function and a method. C<uc("ha")> and C<"ha".uc> both return "HA".
1857+
There is no support for the parameterless version.
1858+
1859+
The Perl 6 ecosystem has a module C<P5lc> which exports a C<uc>
1860+
function that mimics the original Perl 5 behaviour as much as possible.
18271861
18281862
=head2 ucfirst
18291863
18301864
=item ucfirst EXPR
18311865
18321866
=item ucfirst
18331867
1834-
Perl 6 has done away with C<ucfirst>. The title case function L<C<tc>|/routine/tc> probably
1835-
does what you need.
1868+
Perl 6 has done away with C<ucfirst>. The title case function
1869+
L<C<tc>|/routine/tc> probably does what you need.
1870+
1871+
The Perl 6 ecosystem has a module C<P5lcfirst> which exports a C<ucfirst>
1872+
function that mimics the original Perl 5 behaviour as much as possible.
18361873
18371874
=head2 undef
18381875
18391876
=item undef EXPR
18401877
18411878
There is no C<undef> in Perl 6. You can't undefine a function, and the closest
18421879
equivalent value is probably C<Nil>, but you'll likely have no use for that.
1880+
18431881
If you were using something like C<(undef, $file, $line) = caller;>, you would
18441882
just get the filename and line number directly in Perl 6 instead of discarding
18451883
the first result of C<caller>. C<caller> has been replaced by C<callframe> in
@@ -1865,10 +1903,15 @@ The zero argument (implicit C<$_>) version of unlink is not available in Perl 6
18651903
18661904
=item unpack TEMPLATE
18671905
1868-
Available in Perl 6. The template options are currently more restricted
1869-
than they are in Perl 5. The current documented list can be found
1870-
L<here|/routine/unpack>.
1906+
Available in Perl 6 when C<use experimental :pack> has been specified in the
1907+
scope where C<unpack> needs to be called. The template options are currently
1908+
more restricted than they are in Perl 5. The current documented list can be
1909+
found at L<unpack|/routine/unpack>.
18711910
1911+
The Perl 6 ecosystem has a module C<P5pack> which exports a C<unpack>
1912+
function that mimics the original Perl 5 behaviour as much as possible
1913+
and which has a bigger set of supported features than the experimental
1914+
Perl 6 version.
18721915
18731916
=head2 unshift
18741917
@@ -1883,9 +1926,10 @@ equivalent to C<@a.unshift("blah")>.
18831926
18841927
=item untie VARIABLE
18851928
1886-
[NEEDS FURTHER RESEARCH] Functions for tying variables seem to be replaced in
1887-
Perl 6 by container types, as mentioned in S29. This has become no clearer
1888-
since I wrote the entry for C<tie>, above.
1929+
Not supported in Perl 6, but see L<tie> for the whole story.
1930+
1931+
The Perl 6 ecosystem has a module C<P5tie> which exports a C<untie>
1932+
function that mimics the original Perl 5 behaviour as much as possible.
18891933
18901934
=head2 use
18911935
@@ -1920,14 +1964,18 @@ No equivalent.
19201964
Available in Perl 6. Can also be used as a method. C<values %hash> is
19211965
equivalent to C<%hash.values>.
19221966
1923-
19241967
=head2 vec
19251968
19261969
=item vec EXPR, OFFSET, BITS
19271970
1971+
There is no support for vec() in Perl 6.
1972+
19281973
S29 says "Should replace C<vec> with declared buffer/array of C<bit>,
1929-
C<uint2>, C<uint4>, etc." It is unclear, however, that this has actually
1930-
happened.
1974+
C<uint2>, C<uint4>, etc." Support for C<bit>, C<uint2>, C<uint4> has not
1975+
landed yet. But support for C<uint8>, C<int8>, C<uint16>, C<int16>,
1976+
C<uint32>, C<int32>, C<uint64>, C<int64> as well as the system sized
1977+
C<uint> and C<int> B<have> landed. In scalar forms, as well as in array
1978+
and shaped array (aka matrix) forms.
19311979
19321980
=head2 wait
19331981
@@ -2021,7 +2069,7 @@ not advised:
20212069
20222070
=item warn LIST
20232071
2024-
C<warn> throws an exception. To simply print a message to C<$*ERR>, you
2072+
C<warn> throws a resumable exception. To simply print a message to C<$*ERR>, you
20252073
would use the C<note> function. For more on exceptions, see
20262074
L<Exceptions|/language/exceptions>.
20272075

0 commit comments

Comments
 (0)