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.

Alphabetical Listing of Perl Functions

Filetests

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:

'/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:

$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:

$fh.modified# -M $fh 
$fh.accessed# -A $fh 
$fh.changed;  # -C $fh 

The remaining filetests in Perl 5 do not appear to be implemented in Perl 6.

The documentation for this can be found at File test operators.

There is more information on reading and writing files at io. Also, the section on open() below may be helpful.

abs

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 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

[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

Available as a function as well as being able to be used as a method. For instance, these are equivalent:

atan2(100);
100.atan2;

bind

[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

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

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

Not in Perl 6. For breaking out of given blocks, you should probably take a look at proceed and succeed here.

caller

There are a couple different ways to get at caller information in Perl 6. The basic functionality is provided through callframe now. However, Perl 6 constructs call frames for regular blocks, not just for subroutines, so there are more frames to look through. The following will retrieve the basic information that caller can return:

my $frame   = callframe(0); # OR just callframe() 
my ($subroutine$package);
if $frame.code ~~ Routine {
    $subroutine = $frame.code.name;
    $package    = $frame.code.package;
}
my $file    = $frame.file;
my $line    = $frame.line;

Many of the other details returned by caller are specific to Perl 5 and have no meaning in Perl 6.

You can also get some of the information for the current frame or routine frame by using the dynamic variables &?ROUTINE, &?BLOCK, $?PACKAGE, $?FILE, and $?LINE. For many purposes, Backtrace may provide an easier way to browse through the call stack.

chdir

Works as it does in Perl 5.

chmod

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

The behavior of chomp is different than in Perl 5. It leaves the target unaffected and returns a copy of the target with a final logical newline removed, e.g. $x = "howdy\n";$y = chomp($x); results in $x containing "howdy\n" and $y containing "howdy". Also works as a method, e.g. $y = $x.chomp. As with many other methods, also works with assignment to modify the target in place, e.g. $x.=chomp results in $x containing "howdy".

chop

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 is not in Perl 6.

chr

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:

chr(65); # "A" 
65.chr;  # "A" 

chroot

Apparently this is not in Perl 6.

close

As in Perl 5, closes a filehandle. Returns a boolean value. Both close $fh and $fh.close will work.

closedir

Currently, there is no closedir function. When it is implemented, it may well be a method in the IO::Dir class.

connect

Use connect from IO::Socket::Async for an asynchronous socket or create a IO::Socket::INET socket for a synchronous one.

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

Works as in Perl 5, but can be also used as a method, i. e. (1/60000).cos.

crypt

This appears not to have made it into Perl 6.

dbm functions

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

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

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

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 exceptions. To omit the stacktrace and location, like Perl 5's die "...\n", use:

note "...";
exit 1;

do

Similar to the Perl 5 version. Note that there must be a space between the do and the block.

Has been replaced in Perl 6 by EVALFILE.

dump

According to S29, dump has been... dumped.

each

There is no exact equivalent, but you can use %hash.kv which returns a list of keys and values. For example: for %hash.kv -> $k, $v { say "$k: $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

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

Replaced by EVAL. Note that EVAL does not do any exception handling!

evalbytes

No equivalent.

exec

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);.

Neither of these workarounds have the behavior (on Unix-like systems) of replacing your Perl program's process with the new program; notably, they will not work for the practice in some long-running daemons of periodically redoing exec on themselves to reset their state or force operating-system cleanup. Nor will they serve exec's function of returning stale resources to the operating system.

If you want exec for these behaviors, you can use an exec* function via the NativeCall interface. Consult your operating system manual pages for exec (or other similarly-named calls such as execl, execv, execvp, or execvpe). (Beware: these calls are not generally portable between Unix-like operating system families.)

exists

In Perl 6, this is not a function, but an adverb:

%hash{$key}:exists;
@array[$i]:exists;

exit

Appears to do the same thing as in Perl 5.

exp

Same as in Perl 5, but can also be used as a method: 5.exp;

fc

Looks like it does the same thing as in Perl 5.

fcntl

Appears not to be in Perl 6.

__FILE__

Replaced by $?FILE.

fileno

S32 indicates that this should be available as a method, but appears currently unimplemented.

flock

Currently unimplemented.

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

Perl 6 does not have built-in formats.

getc

Reads a single character from the input stream as in Perl 5. May now also be used as a method: $filehandle.getc

getlogin

S29 lists it, but it does not seem to be implemented yet.

getpeername

S29 lists it, but the implementation does not seem clear or, for that matter, implemented.

getpgrp

Does not appear to be implemented.

getpriority

Does not appear to be implemented.

get and set functions

[NEEDS FURTHER RESEARCH] Apparently this range of functions are to be handled by roles like User, Group, etc.

getsock*

[NEEDS FURTHER RESEARCH] These are likely implemented by some kind of IO::Socket object, but details are unclear.

glob

Used in an example in S32, but apparently unimplemented.

gmtime

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

[NEEDS FURTHER RESEARCH] Described in S04, but not yet fully documented.

grep

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

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

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 this section.

index

Works as in Perl 5. Can also now be used as a method: "howdy!".index("how"); # 0

int

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

Currently unimplemented in Perl 6.

join

Works as in Perl 5, and also works as a method: @x.join(",")

keys

Works as in Perl 5, and can also be used as a method: %hash.keys

kill

No pre-defined core alternative exists. A non-portable method can be to use NativeCall:

use NativeCall;
sub kill(int32int32is native {*};
kill $*PID9# OUTPUT: «Killed␤» 

To kill processes that were started by creating a Proc::Async, use Proc::Async.kill method.

last

Same as in Perl 5.

lc

Works as in Perl 5, and also as a method: "UGH".lc

lcfirst

Does not exist in Perl 6.

length

Replaced by chars, typically used as a method ($string.chars), but also works as a function.

__LINE__

Replaced by $?LINE.

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

Not clearly documented, but it appears that listen will be a method you would call on some variety of IO::Socket object.

local

The Perl 6 equivalent is temp. Unlike local, however, the value of the given variable is not immediately unset: it retains its original value until assigned to.

localtime

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

In Perl 6, a method in the Lock class.

log

Available in Perl 6. Also works as a method. I. e. log(2) is equivalent to 2.log.

lstat

Likely implemented somewhere in one of the IO classes in Perl 6, but it is not clear where at this time.

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 Adverbs

map

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

Works as in Perl 5.

The zero argument (implicit $_) version is not permitted in Perl 6.

msg*

Not builtins in Perl 6. May appear in an external module at some point. Maybe.

my

Works as in Perl 5.

next

The same in Perl 6.

no

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

Replaced by the adverbial form :8. E. g. :8("100") returns 64.

If you want to deal with strings that start in 0x, 0o, or 0b, you can just use the prefix:<+> operator.

open

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 here.

opendir

No replacement. See &dir/IO::Path.dir for alternatives.

ord

Same as in Perl 5. May be used as a method: "howdy!".ord; # 104

our

The same in Perl 6.

pack

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 unpack.

package

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__

Replaced by $?PACKAGE.

pipe

Depending on your needs, see Channel to shuttle data between threads (and Concurrency tutorial for other options), or see Proc type for piping to and from processes.

pop

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

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 Continue.

print

print can be used as a function in Perl 6, writing to standard out. To use print as a function with a filehandle instead of standard out, you can use a method call: $fh.print("howdy!")

printf

Perl 6 version is similar; see sprintf for details on acceptable format directives. To print to a filehandle other than STDOUT, use the .printf method on that filehandle.

prototype

Not available in Perl 6. The closest equivalent is .signature. E. g. say &sprintf.signature results in "(Cool $format, *@args)".

push

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

These survive the transition to Perl 6. Some notes:

q/.../ # is still equivalent to using single quotes. 
qq/.../ # is still equivalent to using double quotes. 
qw/.../ # is more commonly rendered as C<< <...> >> in Perl 6. 

There are some added quoting constructs and equivalents, as explained at quoting.

Has been replaced by rx/.../.

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 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 ^ operator and pick.

read

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

Not a builtin function. To iterate through the contents of a directory, take a look at dir routine.

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 io.

Appears to be gone from Perl 6.

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

Appears to be in IO::Socket. Not extensively documented at this time.

redo

Unchanged in Perl 6.

ref

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

Still available in Perl 6.

requires

No equivalent.

reset

No equivalent.

return

Appears to be available in Perl 6, although not clearly documented.

reverse

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

[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

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

Works in Perl 6 and can also be used as a method. rmdir "Foo"; and "Foo".IO.rmdir; are equivalent.

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 Adverbs page

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

Gone. Apparently "very" gone.

seek

Not documented in a any real way yet, but listed under the IO::Handle class.

seekdir

Not currently documented, but looks to be something that would be implemented in one of the IO classes, likely IO::Path.

select

"[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.

semctl

No longer in core.

semget

No longer in core.

semop

No longer in core.

send

Can be found in the IO::Socket class.

setpgrp

No longer in core. Will probably wind up in a POSIX module.

setpriority

No longer in core. Will probably wind up in a POSIX module.

setsockopt

Not documented, but probably hiding in an IO class somewhere.

shift

Works as a method as well as a function. shift @a and @a.shift are equivalent.

shm*

Gone from the core. May turn up in a module somewhere.

shutdown

Not documented, but likely moved into IO::Socket.

sin

Works as a function and also as a method. sin(2) and 2.sin are equivalent.

sleep

Still works as in Perl 5. As of this writing, works as a method, but that is deprecated and will be removed soon.

sockets

Not currently documented, but will likely wind up in IO::Socket.

sort

sort exists in Perl 6, but is somewhat different. $a and $b are no longer special (See 5to6-perlvar) and sort routines no longer return positive integers, negative integers, or 0, but rather Order::Less, Order::Same, or Order::More objects. See sort for details. May also be used as a method I. e. sort(@a) is equivalent to @a.sort.

splice

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

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 here. Unsurprisingly, split also now works as a method: "a;b;c".split(';')

The zero argument version must now be called with an explicit empty string, as described above.

sprintf

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

Works as a function and a method. sqrt(4) and 4.sqrt are equivalent.

srand

Available in Perl 6.

stat

Likely implemented somewhere in IO, but it is not clear where at this time.

state

Available in Perl 6, see state.

study

study is no more.

sub

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 functions.

__SUB__

Replaced by &?ROUTINE.

substr

Can be used as a function or a method. substr("hola!", 1, 3) and "hola!".substr(1, 3) both return "ola".

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

Not a builtin in Perl 6. Most likely out in a module somewhere, but it's currently unclear where.

sys*

As with the non-sys versions of these functions, are probably lurking in the IO classes somewhere.

system

For this, you probably want (run) or (shell routine).

syswrite

As with sysopen and friends, this has moved into the IO classes.

tell

In IO::Handle, but not yet documented, beyond a mention.

telldir

Possibly in IO::Path, but not yet documented.

tie

[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

"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

Not available in Perl 6.

tr///

Works 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

Most likely somewhere in IO::Handle, but not currently documented.

uc

Works as a function and a method. uc("ha") and "ha".uc both return "HA".

ucfirst

Perl 6 has done away with ucfirst. The title case function tc probably does what you need.

undef

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>;

Still available. Usable as a method: "filename".IO.unlink

The zero argument (implicit $_) version of unlink is not available in Perl 6.

unpack

Available in Perl 6. The template options are currently more restricted than they are in Perl 5. The current documented list can be found here.

unshift

Available in Perl 6. Can be used as a method. unshift(@a, "blah") is equivalent to @a.unshift("blah").

untie

[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

In Perl 5, this requires a minimum version of the perl executable in order to run. In Perl 6, this requires a version of the specification, (e.g. 6.c), which can be implemented by various perl6 executables.

utime

No equivalent.

values

Available in Perl 6. Can also be used as a method. values %hash is equivalent to %hash.values.

vec

S29 says "Should replace vec with declared buffer/array of bit, uint2, uint4, etc." It is unclear, however, that this has actually happened.

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

As with wait, the disposition of this is unclear.

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 123;
}
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(123);  # prints "1<2<3" 
print join(">"prettylist(321)); # 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 + 1does 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 throws an exception. To simply print a message to $*ERR, you would use the note function. For more on exceptions, see Exceptions.

write

Formats are gone from Perl 6, so this no longer works.

y///

This synonym for tr/// is gone. For functionality, see the entry for tr///.