5to6-perlfunc
Perl 5 to Perl 6 guide - functions
DESCRIPTION
A (hopefully) comprehensive list of Perl 5 builtin functions with their Perl 6 equivalents with notes on variations between them where necessary.
NOTE
I will not be explaining the functions in detail. This document is an attempt to guide you from the functions in Perl 5's perlfunc document to their equivalents in Perl 6. For full documentation on the Perl 6 functions, please see the Perl 6 documentation.
One general comment: Perl 6 takes its objects a lot more seriously than Perl 5. In Perl 6, everything is an object, although the language is flexible enough to not force you to work in an object oriented manner if you do not wish to do so. What this does mean, however, is that a lot of things that are function calls of the form function(@args) are now also method calls of the form @args.function (In rare cases, there is only a method call). This should be obvious in the following text, but it probably behooves you to get into that frame of mind now.
Also, unless otherwise stated, the use of the term "function" here will mean a function in the style of func(@args), while "method" will refer to a function in the style of @args.func.
SOURCES
I'm taking my information from https://doc.perl6.org, supplemented by the design documents at https://design.perl6.org/ and input from the denizens of #perl6 on irc.freenode.org
Alphabetical Listing of Perl Functions
Filetests
-X FILEHANDLE
-X EXPR
-X DIRHANDLE
-X
Perl 6 gives you a couple of options when it comes to file tests. You can do a smart match (~~) or you can call a method.
In Perl 6, you don't need to actually open a filehandle in the traditional way (although you can) to do a filetest. You can simply append .IO to the filename. For instance, here is how to check if a file is readable using smart match:
C<'/path/to/file'.IO ~~ :r>
You can, of course, use an already opened filehandle. Here, using the file handle $fh, is an example, using the method syntax for the file test:
C<$fh.r>
Most of the former filetests have colon equivalents for use with smart match:
:e Exists
:d Directory
:f File
:l Symbolic link
:r Readable
:w Writable
:x Executable
:s Size
:z Zero size
All of these tests can be used as methods (without the colon).
Three tests, however, only have method equivalents:
C<-M $fh> => C<$fh.modified>
C<-A $fh> => C<$fh.accessed>
C<-C $fh> => C<$fh.changed>
The remaining filetests in Perl 5 do not appear to be implemented in Perl 6.
The documentation for this can be found at https://doc.perl6.org/type/IO::FileTestable#File_Test_operators.
There is more information on reading and writing files at https://doc.perl6.org/language/io. Also, the section on open() below may be helpful.
abs
abs VALUE
Works as a function (abs($x)), but also as a method. One gotcha, however - method calls bind more tightly than -, so, for example, -15.abs evaluates as -(15.abs) giving you -15. In this example, you would have to do something like (-15).abs.
abs also operates on $_ in the absence of a value, but not as a function, and as a method you need to call it as .abs rather than simply abs.
accept
accept NEWSOCKET,GENERICSOCKET
accept is a method you can call on a server, e. g. $server.accept(). Instead of returning a packed address, it returns a socket, most likely an IO::Socket object of some sort.
alarm
alarm SECONDS
[NEEDS FURTHER RESEARCH] alarm() is no more. It has been suggested that a replacement may be somewhere in the new Concurrency features, such as Promise.in, but some digging may be needed to find a true analog.
atan2
atan2 Y,X
Available as a function as well as being able to be used as a method. For instance, these are equivalent:
C<atan2(100)>
C<100.atan2>
bind
bind SOCKET,NAME
[NEEDS FURTHER RESEARCH] No sign of a socket-related bind() in Perl 6. At a guess, whatever socket binding is needed happens when you create a new socket object.
binmode
binmode FILEHANDLE
Instead of this, you would use :bin as the file mode when opening the socket. E. g. my $fh = open("path/to/file", :bin);
bless
bless REF,CLASSNAME
With the changes in class creation in Perl 6, this may find less use than in Perl 5, and is a method as well as a function. The Perl 6 docs say "Creates a new object of the same type as the invocant, uses the named arguments to initialize attributes, and returns the created object." If you're porting a module from Perl 5 to Perl 6, it's quite possible you'll want to use new for creating objects rather than bless, although there may be some situations in which the latter may still be useful.
break
break
Not in Perl 6. For breaking out of given blocks, you should probably take a look at proceed and succeed (https://doc.perl6.org/language/control#proceed_and_succeed).
caller
caller EXPR
[NEEDS FURTHER RESEARCH] What caller does in Perl 5 is taken on by callframe. However, a simple call to callframe will be of little use, as it will return a CallFrame object, rather than any useful information. The filename and line number returned as the second and third values from caller in Perl 5, are in callframe.annotations. You get them by using callframe().annotations.<file line> or, individually, with callframe().annotations.<file> and callframe().annotations.<line> . There does not seem to be a simple way of getting the package name out of callframe however.
chdir
chdir EXPR
Seems to work as it does in Perl 5.
chmod
chmod LIST
Functions as under Perl 5, with the difference that octal numbers are represented differently (0o755 rather than 0755). You may also use it as a method, e. g. $fh.chmod(0o755).
chomp
chomp VARIABLE
The behavior of chomp is different than in Perl 5. It leaves the target unaffected and returns the target with a final logical newline removed. I. e. $x = "howdy\n";$y = chomp($x); results in $x containing "howdy\n" and $y containing "howdy". Also works as a method, i. e. $y = $x.chomp.
chop
chop VARIABLE
As with chomp, in Perl 6, this returns the chopped string, rather than chopping in place. I. e. $x = "howdy";$y = chop($x); results in $x being "howdy" and $y being "howd". Also works as a method: $y = $x.chop
chown
chown LIST
chown is not in Perl 6.
chr
chr NUMBER
Similar to the Perl 5 version, coerces the target to an integer, and uses that as a Unicode code point to return the relevant character. Can be used as a function and a method:
C<chr(65); # "A">
C<65.chr; # "A">
chroot
chroot FILENAME
Apparently this is not in Perl 6.
close
close FILEHANDLE
As in Perl 5, closes a filehandle. Returns a boolean value. Both close $fh and $fh.close will work.
closedir
closedir DIRHANDLE
Currently, there is no closedir function. When it is implemented, it may well be a method in the IO::Dir class.
connect
connect SOCKET,NAME
Not clearly documented, but it appears that connect will be a method you would call on some variety of IO::Socket object.
continue
continue BLOCK
continue
Instead of a continue block, you should use a NEXT block. The closest analog to a bare continue; in Perl 5 appears to be proceed/succeed.
cos
cos EXPR
Works as in Perl 5, but can be also used as a method, i. e. (1/60000).cos.
crypt
crypt PLAINTEXT,SALT
This appears not to have made it into Perl 6.
dbm functions
dbmclose HASH
dbmopen HASH,DBNAME,MASK
These functions have largely been superseded in Perl 5, and are unlikely to ever turn up in Perl 6 (although any assumptions about the Perl 6 database implementation may be premature).
defined
defined EXPR
Probably does what you expect, but technically it returns False on the type object, and True otherwise. This may make more sense when you realize that $num.perl is the type Any if you haven't assigned anything to it, and the assigned value if you have. Can, of course be used as a method: $num.defined
delete
delete EXPR
Perl 6 replaces this with the new adverb syntax, specifically the :delete adverb. E. g. my $deleted_value = %hash{$key}:delete; and my $deleted_value = @array[$i]:delete;.
die
die LIST
Works similarly to the Perl 5 version, but Perl 6's Exception mechanism may give you more power and flexibility than is available in Perl 5. See https://doc.perl6.org/language/exceptions.
do
do BLOCK
Similar to the Perl 5 version. Note that there must be a space between the do and the block.
do EXPR
Has been replaced in Perl 6 by EVALFILE.
dump
dump LABEL
According to S29, dump has been... dumped.
each
each HASH
There is no exact equivalent. The closest is probably <%hash.kv> which returns a list of keys and values. Ergo: for %hash.kv - $k, $v { #do stuff with $k and $v }>
Incidentally, what we have there with the -> is called a pointy block and, though there are a number of examples in the documentation, there doesn't seem to be a really clear explanation of how they work. https://design.perl6.org/S04.html#The_for_statement may be of some help here, as well as the design document at https://design.perl6.org/S06.html#%22Pointy_blocks%22. There is also some information at https://en.wikibooks.org/wiki/Perl_6_Programming/- Blocks_and_Closures#Pointy_Blocks
eof
eof FILEHANDLE
In Perl 6, this is not usable as a function, but only as a method. I. e. $filehandle.eof. Returns True if at end of file.
eval
eval EXPR
eval EXPR
Replaced by EVAL. Note that EVAL does not do any exception handling!
evalbytes
evalbytes EXPR
No longer seems to exist.
exec
exec LIST
Nothing in Perl 6 exactly replicates the Perl 5 exec. shell and run are similar to Perl 5's system, but exec's behavior of not returning after executing a system command would have to be emulated by something like shell($command);exit(); or possibly exit shell($command);
exists
exists EXPR
In Perl 6, this is not a function, but an adverb:
C<%hash{$key}:exists;>
C<@array[$i]:exists;>
exit
exit EXPR
Appears to do the same thing as in Perl 5.
exp
exp EXPR
Same as in Perl 5, but can also be used as a method: 5.exp;
fc
fc EXPR
Looks like it does the same thing as in Perl 5.
fcntl
fcntl FILEHANDLE,FUNCTION,SCALAR
Appears not to be in Perl 6.
__FILE__
__FILE__
Replaced by $?FILE.
fileno
fileno FILEHANDLE
S32 indicates that this should be available as a method, but appears currently unimplemented.
flock
flock FILEHANDLE,OPERATION
Currently unimplemented.
fork
fork
Not implemented as a built in function, but available through the NativeCall interface. E. g. use NativeCall; sub fork returns int32 is native { * }; say fork;.
formats
format
formline PICTURE,LIST
Perl 6 does not have built-in formats.
getc
getc FILEHANDLE
Reads a single character from the input stream as in Perl 5. May now also be used as a method: $filehandle.getc
getlogin
getlogin
S29 lists it, but it does not seem to be implemented yet.
getpeername
getpeername SOCKET
S29 lists it, but the implementation does not seem clear or, for that matter, implemented.
getpgrp
getpgrp PID
Does not appear to be implemented.
getpriority
getpriority WHICH,WHO
Does not appear to be implemented.
get and set functions
getpwnam NAME
getgrnam NAME
gethostbyname NAME
getnetbyname NAME
getprotobyname NAME
getpwuid UID
getgrgid GID
getservbyname NAME,PROTO
gethostbyaddr ADDR,ADDRTYPE
getnetbyaddr ADDR,ADDRTYPE
getprotobynumber NUMBER
getservbyport PORT,PROTO
getpwent
getgrent
gethostent
getnetent
getprotoent
getservent
setpwent
setgrent
sethostent STAYOPEN
setnetent STAYOPEN
setprotoent STAYOPEN
setservent STAYOPEN
endpwent
endgrent
endhostent
endnetent
endprotoent
endservent
[NEEDS FURTHER RESEARCH] Apparently this range of functions are to be handled by roles like User, Group, etc.
getsock*
getsockname SOCKET
getsockopt SOCKET,LEVEL,OPTNAME
[NEEDS FURTHER RESEARCH] These are likely implemented by some kind of IO::Socket object, but details are unclear.
glob
glob EXPR
Used in an example in S32, but apparently unimplemented.
gmtime
gmtime EXPR
Like the various parts of localtime, gmtime's functionality appears to in the DateTime object. To get a UTC version of a DateTime object for the current time, for instance, use my $gmtime = DateTime.now.utc.
goto
goto LABEL
goto EXPR
goto &NAME
[NEEDS FURTHER RESEARCH] Described in S04, but not yet fully documented.
grep
grep BLOCK LIST
grep EXPR,LIST
Still in Perl 6, with the caveat that the block form now requires a comma after the block. I.e. @foo = grep { $_ = "bars" }, @baz. Can also be used as a method: @foo = @bar.grep(/^f/)
hex
hex EXPR
Replaced by the adverbial form :16. E. g. :16("aF") returns 175.
Alternately, the same result can be achieved by using the .base method: 0xaF.base(10)
It just so happens that .Str defaults to base 10, so if you just say 0xaF, that will also print 175, but that may not be immediately obvious, so may not be the best way to go for this.
import
import LIST
Was never a builtin function in Perl 5 in the first place. In Perl 6, typically, one declares functions as exportable or not, and all the exportable ones are exported. Nevertheless, selective importing is possible, but beyond the scope of this document. For details, see - https://doc.perl6.org/language/5to6#Importing_specific_functions_from- _a_module.
index
index STR,SUBSTR,POSITION
Works as in Perl 5. Can also now be used as a method: "howdy!".index("how"); # 0
int
int EXPR
There is a truncate function in Perl 6 (also usable as a method) that does what Perl 5's int does. You may want to use that as a direct translation of Perl 5 code, but in Perl 6, you can just as easily call the .Int method on the number. 3.9.Int; # 3 and 3.9.truncate are equivalent.
ioctl
ioctl FILEHANDLE,FUNCTION,SCALAR
Currently unimplemented in Perl 6.
join
join EXPR,LIST
Works as in Perl 5, and also works as a method: @x.join(",")
keys
keys HASH
Works as in Perl 5, and can also be used as a method: %hash.keys
kill
kill SIGNAL, LIST
kill SIGNAL
Now part of the Proc::ASync class, but looks to work as in Perl 5.
last
last LABEL
last EXPR
last
Same as in Perl 5.
lc
lc EXPR
Works as in Perl 5, and also as a method: "UGH".lc
lcfirst
lcfirst EXPR
Does not exist in Perl 6.
length
length EXPR
Replaced by chars, typically used as a method ($string.chars), but also works as a function.
__LINE__
__LINE__
Replaced by $?LINE.
link
link OLDFILE,NEWFILE
In Perl 6, part of the IO::Path class. The only difference between Perl 5 and Perl 6 is that the argument order has changed. It's now link($original, $linked_file).
listen
listen SOCKET,QUEUESIZE
Not clearly documented, but it appears that listen will be a method you would call on some variety of IO::Socket object.
local
local EXPR
The Perl 6 equivalent is temp.
localtime
localtime EXPR
Most of the functionality of localtime is found in DateTime. The specific parts of localtime can be found as follows:
my $d = DateTime.now;
$sec = $d.second; # Potentially includes fractional seconds
$min = $d.minute;
$hour = $d.hour;
$mday = $d.day-of-month; # or $d.day; 1..31
$mon = $d.month; # 1..12
$year = $d.year;
$wday = $d.day-of-week; # 1 => Monday, 2 => Tuesday, etc.
$yday = $d.day-of-year; # 1..366
Please note that ranges are not 0-based in Perl 6, as shown in the comments in the example.
There does not currently appear to be a way to get Perl 5's $isdst. Also, the result of scalar(localtime) that Perl 5 provides is not available. $d.Str will give something along the lines of "2015-06-29T12:49:31-04:00".
lock
lock THING
In Perl 6, a method in the Lock class.
log
log EXPR
Available in Perl 6. Also works as a method. I. e. log(2) is equivalent to 2.log.
lstat
lstat FILEHANDLE
lstat EXPR
lstat DIRHANDLE
lstat
Likely implemented somewhere in one of the IO classes in Perl 6, but it is not clear where at this time.
m//
m//
Regular expression syntax is somewhat different in Perl 6, but the match operator still exists. If you're trying to rewrite some Perl 5 code, the most important difference is that =~ is replaced by the smart match operator, ~~. Similarly, !~ is replaced by !~~. Options for regex operators are adverbs and are complicated. For details, see https://doc.perl6.org/language/regexes#Adverbs
map
map BLOCK LIST
map EXPR,LIST
As a function, the only difference between Perl 5 and Perl 6 is that, if you're using a block, the block must be followed by a comma. Can also be used as a method: @new = @old.map: { $_ * 2 }
mkdir
mkdir FILENAME,MASK
mkdir FILENAME
Works as in Perl 5.
mkdir
The zero argument (implicit $_) version is not permitted in Perl 6.
msg*
msgctl ID,CMD,ARG
msgget KEY,FLAGS
msgrcv ID,VAR,SIZE,TYPE,FLAGS
msgsnd ID,MSG,FLAGS
Not builtins in Perl 6. May appear in an external module at some point. Maybe.
my
my VARLIST
my TYPE VARLIST
my VARLIST : ATTRS
my TYPE VARLIST : ATTRS
Works as in Perl 5.
next
next LABEL
next EXPR
next
The same in Perl 6.
no
no MODULE VERSION
no MODULE LIST
no MODULE
no VERSION
In Perl 6, this is usable for pragmas such as strict, but not for modules. It's unclear whether it can be used for versions, but since that's currently something of a moot point, I would guess not.
oct
oct
Replaced by the adverbial form :8. E. g. :8("100") returns 64.
open
open FILEHANDLE,EXPR
open FILEHANDLE,MODE,EXPR
open FILEHANDLE,MODE,EXPR,LIST
open FILEHANDLE,MODE,REFERENCE
open FILEHANDLE
The most obvious change from Perl 5 is the file mode syntax. To open a file for reading only, you would say open("file", :r). For write- only, read-write, and append, you would use :w, :rw, and :a respectively. There are also options for encoding and how the filehandle deals with newlines. Details at https://doc.perl6.org/routine/open.
opendir
opendir DIRHANDLE,EXPR
Not a builtin function in Perl 6. You would use the IO::Path class:
C<my $dir = IO::Path.new("directory")>
C<my $dir = "directory".IO; # Same, but probably more direct>
ord
ord EXPR
Same as in Perl 5. May be used as a method: "howdy!".ord; # 104
our
our VARLIST
our TYPE VARLIST
our VARLIST : ATTRS
our TYPE VARLIST : ATTRS
The same in Perl 6.
pack
pack TEMPLATE,LIST
Available in Perl 6. The template options are currently more restricted than they are in Perl 5. The current documented list can be found at https://doc.perl6.org/routine/unpack.
package
package NAMESPACE
package NAMESPACE VERSION
package NAMESPACE BLOCK
package NAMESPACE VERSION BLOCK
S10 indicates that package can be used in Perl 6, but only with a block. I. e. package Foo { ... } means that the code within the block would be in package Foo. There is a special case where a declaration of the form package Foo; as the first statement in a file indicates that the rest of the file is Perl 5 code, but the usefulness of this is unclear. In fact, as modules and classes are declared with distinct keywords (such as class), it's unlikely you will use package directly in Perl 6.
__PACKAGE__
__PACKAGE__
Replaced by $?PACKAGE.
pipe
pipe READHANDLE,WRITEHANDLE
Probably replaced by something in the IO::Pipe class, but this is not clearly documented.
pop
pop ARRAY
Works in Perl 6, and can also be used as a method. I. e. my $x = pop @a; and my $x = @a.pop; are equivalent.
pos
pos SCALAR
Not available in Perl 6. The closest equivalent is the :c adverb, which defaults to $/.to if $/ is true, and 0 if it isn't. For information on :c, see https://doc.perl6.org/language/regexes#Continue.
print FILEHANDLE LIST
print FILEHANDLE
print LIST
print
print can be used as a function in Perl 6, defaulting to standard out. To use print as a function with a filehandle instead of standard out, you need to put a colon after the filehandle. I. e. print $fh: "Howdy!". The use of the colon as an "invocant marker" here is discussed at https://design.perl6.org/S03.html#line_4019. Alternately, you can use a method call: $fh.print("howdy!")
printf
printf FILEHANDLE
printf FORMAT, LIST
printf
Works in Perl 6. For the formats, see the documentation for sprintf.
prototype
prototype FUNCTION
No available in Perl 6. The closest equivalent seems to be .signature. E. g. say &sprintf.signature results in "(Cool $format, *@args)".
push
push ARRAY,LIST
Works as in Perl 5, as well as being available as a method: @a.push("foo");. Note: the flattening behaviour is different in Perl 6: @b.push: @a will push @a into @b as a single element. See also the append method.
quoting
q/STRING/
qq/STRING/
qw/STRING/
qx/STRING/
These survive the transition to Perl 6. Some notes:
C<q/.../> is still equivalent to using single quotes.
C<qq/.../> is still equivalent to using double quotes.
C<qw/.../> is more commonly rendered as C<< <...> >> in Perl 6.
There are some added quoting constructs and equivalents, as explained at https://doc.perl6.org/language/quoting.
qr/STRING/
Has been replaced by rx/.../.
quotemeta EXPR
No direct equivalent, i.e. nothing that just returns the string with all the ASCII non-word characters backslashed. In regexes, however, using $foo will treat $foo as a literal string, and using <$foo> will interpret the contents of $foo as regex code. Note that the angle brackets are doing something different here than they do outside a regex. For more information on this, see https://design.perl6.org/S05.html#Extensible_metasyntax_(%3C...%3E)
rand
rand EXPR
rand by itself works as it does in Perl 5, but you can no longer give it an argument. You can, however, use it as a method on a number to get that behavior. I. e. the Perl 5 rand(100) is equivalent to 100.rand in Perl 6. Additionally, you can get a random integer by using something like (^100).pick. For why you are able to do that, see https://doc.perl6.org/language/operators#prefix_%5E and https://doc.perl6.org/routine/pick.
read
read FILEHANDLE,SCALAR,LENGTH,OFFSET
read is found in IO::Handle and IO::Socket in Perl 6. It reads the specified number of bytes (rather than characters) from the relevant handle or socket. The use of an offset available in Perl 5 is not documented to exist at this time.
readdir
readdir DIRHANDLE
Not a builtin function. To iterate through the contents of a directory, take a look at https://doc.perl6.org/type/IO::Path#routine_dir.
readline
readline
Not available in Perl 6. You most likely want to use the .lines method in some way. For more detailed information on reading from files, see https://doc.perl6.org/language/io.
readlink
readlink EXPR
Appears to be gone from Perl 6.
readpipe
readpipe EXPR
readpipe
Doesn't appear to be working in Perl 6, but qx// is functional, so it might be lurking around in some class that isn't obvious.
recv
recv SOCKET,SCALAR,LENGTH,FLAGS
Appears to be in IO::Socket. Not extensively documented at this time.
redo
redo LABEL
redo EXPR
redo
Unchanged in Perl 6.
ref
ref EXPR
Gone. To quote S29, "If you really want the type name, you can use $var.WHAT.perl. If you really want P5 ref semantics, use Perl5::p5ref." Except that Perl5::p5ref does not seem to currently exist...
rename
rename OLDNAME,NEWNAME
Still available in Perl 6.
requires
require VERSION
Seems that require may work for modules in Perl 6, but unclear if it will work with version numbers.
reset
reset EXPR
Seeing no evidence of this in Perl 6 and, in fact, S29 asks if there was a good use for this. I'm guessing it's probably gone.
return
return EXPR
Appears to be available in Perl 6, although not clearly documented.
reverse
reverse LIST
In Perl 6, this only reverses the elements of a list. reverse(@a) or @a.reverse. To reverse the characters in a string, use the .flip method.
rewinddir
rewinddir DIRHANDLE
[NEEDS FURTHER RESEARCH] There does not appear to be an obvious direct equivalent. It is possible that some incantation in IO::Path may serve, but it's not clear what it would be.
rindex
rindex STR,SUBSTR,POSITION
Works as in Perl 5, and may also be used as a method. E. g. $x = "babaganush";say $x.rindex("a");say $x.rindex("a", 3); # 5, 3
rmdir
rmdir FILENAME
Works in Perl 6 and can also be used as a method. rmdir "Foo"; and "Foo".IO.rmdir; are equivalent.
s///
s///
Regular expression syntax is somewhat different in Perl 6, but the substitution operator exists. If you're trying to rewrite some Perl 5 code, the most important difference is that =~ is replaced by the smart match operator, ~~. Similarly, !~ is !~~. Options for regex operators are adverbs and are complicated. For details, see https://doc.perl6.org/language/regexes#Adverbs
say
say FILEHANDLE
say LIST
say
say can be used as a function, defaulting to standard out. To use say as a function with a filehandle instead of standard out, you need to put a colon after the filehandle. I. e. say $fh: "Howdy!". The use of the colon as an "invocant marker" here is discussed at https://design.perl6.org/S03.html#line_4019. Alternately, you can use a method call: $fh.say("howdy!")
scalar
scalar EXPR
Gone. Apparently "very" gone.
seek
seek FILEHANDLE,POSITION,WHENCE
Not documented in a any real way yet, but listed under the IO::Handle class.
seekdir
seekdir DIRHANDLE,POS
Not currently documented, but looks to be something that would be implemented in one of the IO classes, likely IO::Path.
select
select FILEHANDLE
"[S]elect as a global concept is dead." When I asked around about select, I was told that $*OUT and such are overridable in dynamic scope, and that IO::Capture::Simple (at https://github.com/sergot/IO-Capture-Simple) may be of use for something you might be doing with the value of select.
sem*
semctl ID,SEMNUM,CMD,ARG
semget KEY,NSEMS,FLAGS
semop KEY,OPSTRING
Gone from the core. May turn up in a module somewhere.
send
send SOCKET,MSG,FLAGS,TO
Can be found in the IO::Socket class.
setpgrp
setpgrp PID,PGRP
No longer in core. Will probably wind up in a POSIX module.
setpriority
setpriority WHICH,WHO,PRIORITY
No longer in core. Will probably wind up in a POSIX module.
setsockopt
setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL
Not documented, but probably hiding in an IO class somewhere.
shift
shift ARRAY
shift EXPR
shift
Works as a method as well as a function. shift @a and @a.shift are equivalent.
shm*
shmctl ID,CMD,ARG
shmget KEY,SIZE,FLAGS
shmread ID,VAR,POS,SIZE
shmwrite ID,STRING,POS,SIZE
Gone from the core. May turn up in a module somewhere.
shutdown
shutdown SOCKET,HOW
Not documented, but likely moved into IO::Socket.
sin
sin EXPR
Works as a function and also as a method. sin(2) and 2.sin are equivalent.
sleep
sleep EXPR
Still works as in Perl 5. As of this writing, works as a method, but that is deprecated and will be removed soon.
sockets
socket SOCKET,DOMAIN,TYPE,PROTOCOL
socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL
Not currently documented, but will likely wind up in IO::Socket.
sort
sort SUBNAME LIST
sort exists in Perl 6, but is somewhat different. $a and $b are no longer special (See 5to6-perlvar.pod) and sort routines no longer return positive integers, negative integers, or 0, but rather Order::Increase, Order::Same, or Order::Decrease objects. See https://doc.perl6.org/routine/sort for details. May also be used as a method I. e. sort(@a) is equivalent to @a.sort.
splice
splice ARRAY,OFFSET,LENGTH
splice ARRAY,OFFSET
splice ARRAY
splice EXPR,OFFSET,LENGTH,LIST
splice EXPR,OFFSET,LENGTH
splice EXPR,OFFSET
splice EXPR
Available in Perl 6. Can also be used as a method. splice(@foo, 2,3, <M N O P>); is equivalent to @foo.splice(2, 3, <M N O P>); .
split
split /PATTERN/,EXPR,LIMIT
split /PATTERN/,EXPR
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 // being treated as the empty string does not apply. If you use a regex for the split, it will use the regex, while a literal string will be treated literally. If you wish to have the delimiters included in the resulting list, you need to use the named parameter :all, like this: split(';', "a;b;c", :all) # a ; b ; c Empty chunks are not removed from the result list as they are in Perl 5. For that behavior, see comb. Details on split are at https://doc.perl6.org/routine/split. Unsurprisingly, split also now works as a method: "a;b;c".split(';')
split
The zero argument version must now be called with an explicit empty string, as described above.
sprintf
sprintf FORMAT, LIST
Works as in Perl 5. The formats currently available are:
% a literal percent sign
c a character with the given codepoint
s a string
d a signed integer, in decimal
u an unsigned integer, in decimal
o an unsigned integer, in octal
x an unsigned integer, in hexadecimal
e a floating-point number, in scientific notation
f a floating-point number, in fixed decimal notation
g a floating-point number, in %e or %f notation
X like x, but using uppercase letters
E like e, but using an uppercase "E"
G like g, but with an uppercase "E" (if applicable)
Compatibility:
i a synonym for %d
D a synonym for %ld
U a synonym for %lu
O a synonym for %lo
F a synonym for %f
Perl 5 (non-)compatibility:
n produces a runtime exception
p produces a runtime exception
There are modifiers for integers, but they're mainly no-ops, as the semantics aren't settled:
h interpret integer as native "short" (typically int16)
l interpret integer as native "long" (typically int32 or int64)
ll interpret integer as native "long long" (typically int64)
L interpret integer as native "long long" (typically uint64)
q interpret integer as native "quads" (typically int64 or larger)
sqrt
sqrt EXPR
Works as a function and a method. sqrt(4) and 4.sqrt are equivalent.
srand
srand EXPR
Available in Perl 6.
stat
stat EXPR
stat DIRHANDLE
stat
Likely implemented somewhere in IO, but it is not clear where at this time.
state
state VARLIST
state TYPE VARLIST
state VARLIST : ATTRS
state TYPE VARLIST : ATTRS
Available in Perl 6, but currently not documented.
study
study SCALAR
study
study is no more.
sub
sub NAME BLOCK
sub NAME (PROTO) BLOCK
sub NAME : ATTRS BLOCK
sub NAME (PROTO) : ATTRS BLOCK
Unsurprisingly, we still have subroutines! You can have a signature in your subroutine which allows you to specify arguments. Nevertheless, in the absence of a signature (and only in the absence of a signature), @_ still contains what is passed to the function. So, in theory, you don't need to change that aspect of a function if porting from Perl 5 to Perl 6 (although you should probably consider the option of using a signature). For all the gory details, see https://doc.perl6.org/language/functions.
__SUB__
__SUB__
Replaced by &?ROUTINE.
substr
substr EXPR,OFFSET,LENGTH,REPLACEMENT
substr EXPR,OFFSET,LENGTH
substr EXPR,OFFSET
Can be used as a function or a method. substr("hola!", 1, 3) and "hola!.substr(1, 3) both return "ola".
symlink
symlink OLDFILE,NEWFILE
Part of IO::Path in Perl 6. The only difference between Perl 5 and Perl 6 is that the argument order has changed. It's now link($original, $linked_file).
syscall
syscall NUMBER, LIST
Not a builtin in Perl 6. Most likely out in a module somewhere, but it's currently unclear where.
sys*
sysopen FILEHANDLE,FILENAME,MODE
sysopen FILEHANDLE,FILENAME,MODE,PERMS
sysread FILEHANDLE,SCALAR,LENGTH,OFFSET
sysread FILEHANDLE,SCALAR,LENGTH
sysseek FILEHANDLE,POSITION,WHENCE
As with the non-sys versions of these functions, are probably lurking in the IO classes somewhere.
system
system LIST
system PROGRAM LIST
For this, you probably want run (https://doc.perl6.org/routine/run) or shell (https://doc.perl6.org/routine/shell).
syswrite
syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET
syswrite FILEHANDLE,SCALAR,LENGTH
syswrite FILEHANDLE,SCALAR
As with sysopen and friends, this has moved into the IO classes.
tell
tell FILEHANDLE
In IO::Handle, but not yet documented, beyond a mention.
telldir
telldir DIRHANDLE
Possibly in IO::Path, but not yet documented.
tie
tie VARIABLE,CLASSNAME,LIST
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.
time
time
"Returns an Int representing the current time." Although how it represents the current time isn't in the documentation currently, it appears to still be seconds since epoch, as in Perl 5.
times
times
Not available in Perl 6.
tr///
tr///
Not well documented in this form, but seems to work similarly to how it does in Perl 5. The one caveat is that ranges are specified differently. Instead of using a range "a-z", you would use "a..z", i. e. with Perl's range operator. In Perl 6, tr/// has a method version, which is better documented, called .trans. .trans uses a list of pairs, as follows: $x.trans(['a'..'c'] => ['A'..'C'], ['d'..'q'] => ['D'..'Q'], ['r'..'z'] => ['R'..'Z']); A much more extensive description of the uses of .trans can be found at https://design.perl6.org/S05.html#Transliteration. The y/// equivalent has been done away with.
truncate
truncate FILEHANDLE,LENGTH
truncate EXPR,LENGTH
Most likely somewhere in IO::Handle, but not currently documented.
uc
uc EXPR
Works as a function and a method. uc("ha") and "ha".uc both return "HA".
ucfirst
ucfirst EXPR
ucfirst
Perl 6 has done away with ucfirst. The title case function tc probably does what you need here. https://doc.perl6.org/routine/tc
umask
umask EXPR
Is an IO method. IO.umask returns the umask.
undef
undef EXPR
There is no undef in Perl 6. You can't undefine a function, and the closest equivalent value is probably Nil, but you'll likely have no use for that. If you were using something like (undef, $file, $line) = caller;, you would just get the filename and line number directly in Perl 6 instead of discarding the first result of caller. caller has been replaced by callframe in Perl 6, so the equivalent statement would be ($file, $line) = callframe.annotations<file line>;
unlink
unlink LIST
Still available. Usable as a method: "filename".IO.unlink
unlink
The zero argument (implicit $_) version of unlink is not available in Perl 6.
unpack
unpack TEMPLATE,EXPR
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 at https://doc.perl6.org/routine/unpack.
unshift
unshift ARRAY,LIST
unshift EXPR,LIST
Available in Perl 6. Can be used as a method. unshift(@a, "blah") is equivalent to @a.unshift("blah").
untie
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 tie, above.
use
use Module VERSION LIST
use Module VERSION
use Module LIST
use Module
use VERSION
Available in Perl 6, but, oddly, not yet documented. One assumes it works similarly, if not identically, to the way it does in Perl 5
utime
utime LIST
S32 says this is gone, and refers you to Path.times. Unfortunately, there seems to be no sign of Path.times. Perhaps there will be something in IO::Path, but it is not currently evident.
values
values HASH
values ARRAY
values EXPR
Available in Perl 6. Can also be used as a method. values %hash is equivalent to %hash.values.
vec
vec EXPR,OFFSET,BITS
S29 says "Should replace vec with declared buffer/array of bit, uint2, uint4, etc." It is unclear, however, that this has actually happened.
wait
wait
[NEEDS FURTHER RESEARCH] Unclear where this has gone. There's a wait method in Supply, and an await method in both Channel and Promise. Which, if any or all, of these is a direct equivalent of Perl 5's wait is unclear.
waitpid
waitpid PID,FLAGS
As with wait, the disposition of this is unclear.
wantarray
wantarray
There is no wantarray in Perl 6, because reasons.
There are very easy ways to cover many of the use cases which wantarray filled.
First, since Perl 6 does not need special reference syntax to contain a List or Array in a Scalar, simply returning a list may be all that is needed:
sub listofstuff {
return 1,2,3;
}
my $a = listofstuff();
print $a; # prints "123"
print join("<",listofstuff()) # prints "1<2<3"
One of the most common use cases is to provide either an array of lines or elements, or a prettier string than would be produced by simply printing the array. One can mix in a custom .Str method for this purpose:
sub prettylist(*@origlist) {
@origlist but role {
method Str { self.join("<") }
}
}
print prettylist(1,2,3); # prints "1<2<3"
print join(">", prettylist(3,2,1)); # prints "3>2>1"
In the above example, the returned list may be lazy, and the .Str method is not called until stringification happens, so no extra work is done to generate something which is not asked for.
Another use case is to create methods which are mutators when called in void context but produce copies during assignment. It is generally considered better form in Perl 6 not to do so, since users can quite easily turn any copy-producing method into a mutator using the .= operator:
my $a = "foo\n";
$a.ords.say; # says "(102 111 111 10)"
$a .= chomp;
$a.ords.say; # says "(102 111 111)"
However if you have your heart set on using the same function name for both operations, you can get most of the way there by mixing in a .sink method, which will be called when the result finds itself in void context. There are some caveats however, so again, this is not advised:
multi sub increment($b is rw) {
($b + 1) does role { method sink { $b++ } }
}
multi sub increment($b) {
$b + 1
}
my $a = 1;
increment($a);
say $a; # says "2"
my $b = increment($a);
say $a, $b; # says "2 3"
# ...users will just have to be aware that they should not accidentally
# sink a stored value later, though this requires some effort to
# actually do:
sub identity($c is rw) { $c };
$a = 1;
$b = increment($a);
identity($b);
$a.say; # says "2"
warn
warn LIST
warn throws an exception. To simply print a message to $*ERR, you would use the note function. For more on exceptions, see https://doc.perl6.org/language/exceptions.
write
write FILEHANDLE
write EXPR
write
Formats are gone from Perl 6, so this no longer works.
y///
y///
This synonym for tr/// is gone. For functionality, see the entry for tr///.


Perl 6 Documentation