=begin pod :kind("Language") :subkind("Language") :category("migration")

=TITLE Perl to Raku guide - functions

=SUBTITLE Builtin functions in Perl to Raku

=head1 DESCRIPTION

A (hopefully) comprehensive list of Perl builtin functions with their Raku
equivalents with notes on variations between them where necessary.

=head1 NOTE

This document is an
attempt to guide you from the functions in Perl's C<perlfunc> document to
their equivalents in Raku. For full documentation on the Raku
functions, follow the links in this document to their respective documentation.

One general comment: Raku takes its objects a lot more seriously than
Perl. In Raku, 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 C<function(@args)> are now
also method calls of the form C<@args.function> (In rare cases, there is
I<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 C<func(@args)>, while "method" will refer to a
function in the style of C<@args.func>.

=head1 Alphabetical listing of Perl functions

X<|filetests - perlfunc>
=head2 Filetests

=item -X FILEHANDLE

=item -X EXPR

=item -X DIRHANDLE

=item -X

Raku gives you a couple of options when it comes to file tests. You can do a
smartmatch (C<~~>) or you can call a method.

In Raku, you don't need to actually open a filehandle in the
traditional way (although you can) to do a filetest. You can simply append
C<.IO> to the filename. For instance, here is how to check if a file is
readable using smartmatch:

    '/path/to/file'.IO ~~ :r

You can, of course, use an already opened filehandle. Here, using the filehandle
C<$fh>, is an example, using the method syntax for the file test:

=for code :preamble<my $fh;>
$fh.r

Most of the former filetests have colon equivalents for use with smartmatch:

=table
    :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, I<only> have method equivalents:

=for code :preamble<my $fh;>
$fh.modified; # -M $fh
$fh.accessed; # -A $fh
$fh.changed;  # -C $fh

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

The documentation for this can be found at
L<File test operators|/type/IO::Path#File_test_operators>.

There is more information on reading and writing files at
L<io|/language/io>. Also, the section on C<open()>
below may be helpful.

The Raku ecosystem has a module L<C<P5-X>|https://modules.raku.org/dist/P5-X>
which exports the behavior as much as possible in Raku.

X<| abs - perlfunc>
=head2 abs

=item abs VALUE

Works as a function (C<abs($x)>), but also as a method. One gotcha,
however - method calls bind more tightly than C<->, so, for example,
C<-15.abs> evaluates as C<-(15.abs)> giving you C<-15>. In this example, you
would have to do something like C<(-15).abs>.

C<abs> also operates on C<$_> in the absence of a value, but not as a
function, and as a method you need to call it as C<.abs> rather than simply
C<abs>.

The Raku ecosystem has a module L<C<P5math>|https://modules.raku.org/dist/P5math>
which exports an C<abs> function that mimics the original Perl behavior as
much as possible.

X<| accept - perlfunc>
=head2 accept

=item accept NEWSOCKET, GENERICSOCKET

C<accept> is a method you can call on a server, e. g.
C<$server.accept()>. Instead of returning a packed address, it returns a
socket, most likely an IO::Socket object of some sort.

X<| alarm - perlfunc>
=head2 alarm

=item alarm SECONDS

C<alarm()> is no more.  But it is possible to have code execute after a
certain time has elapsed, or at a given time:

  Promise.in(5).then: { say "five seconds have passed" }

  Promise.at(now + 5).then: { say "five seconds have passed" }

In Raku, this does *not* involve any (dummy) signals.

X<| atan2 - perlfunc>
=head2 atan2

=item atan2 Y, X

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

    atan2(100);
    100.atan2;

X<| bind - perlfunc>
=head2 bind

=item bind SOCKET, NAME

[NEEDS FURTHER RESEARCH] No sign of a socket-related C<bind()> in Raku. At a
guess, whatever socket binding is needed happens when you create a new socket
object.

X<| binmode - perlfunc>
=head2 binmode

=item binmode FILEHANDLE

Instead of this, you would use C<:bin> as the file mode when opening the
socket. E. g. C<my $fh = open("path/to/file", :bin);>

X<| bless - perlfunc>
=head2 bless

=item bless REF, CLASSNAME

With the changes in class creation in Raku, this may find less use
than in Perl, and is a method as well as a function. The Raku 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 to Raku, it's quite
possible you'll want to use C<new> for creating objects rather than
C<bless>, although there may be some situations in which the latter may
still be useful.

X<| break - perlfunc>
=head2 break

=item break

It does not exist in Raku. For breaking out of C<given> blocks, you should
probably take a look at
L<C<proceed> and C<succeed>|/language/control#index-entry-control_flow__proceed-proceed>.

X<| caller - perlfunc>
=head2 caller

=item caller EXPR

There are a couple different ways to get at caller information in Raku.
The basic functionality is provided through L<callframe|/routine/callframe> now. However, Raku
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 C<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 C<caller> are specific to Perl and have
no meaning in Raku.

You can also get some of the information for the current frame or routine frame
by using the dynamic variables
L«C<&?ROUTINE>|/language/variables#Compile-time_variables»,
L«C<&?BLOCK>|/language/variables#Compile-time_variables»,
L«C<$?PACKAGE>|/language/variables#Compile-time_variables»,
L«C<$?FILE>|/language/variables#Compile-time_variables», and
L«C<$?LINE>|/language/variables#Compile-time_variables». For many purposes,
L<Backtrace|/type/Backtrace> may provide an easier way to browse through the call stack.

The Raku ecosystem has a module L<C<P5caller>|https://modules.raku.org/dist/P5caller>
which exports a C<caller> function that mimics the original Perl behavior
as much as possible.

X<| chdir - perlfunc>
=head2 chdir

=item chdir EXPR

Works as it does in Perl but B<must> take an argument.  The behavior
of C<chdir()> (with regards to looking at HOME and LOGDIR) is not supported.

In Raku, L<chdir|/routine/chdir> only changes the C<$*CWD> dynamic variable.  It does
B<not> actually change the default directory from the OS's point of view; the
special dynamic-variable routine L«C<&*chdir>|/routine/&*chdir» can be used
for that, if needed.

This is done this way, because there is no concept of a "default directory
per OS thread".  And since Raku does not fork, but only does threading,
it was felt that the "current directory" concept should be in the C<$*CWD>
dynamic variable, which can be lexically scoped, and thus can be thread-safe.

The Raku ecosystem has a module L<C<P5chdir>|https://modules.raku.org/dist/P5chdir>
which exports a C<chdir> function that mimics the original Perl behavior
as much as possible, including looking at HOME and LOGDIR.

X<| chmod - perlfunc>
=head2 chmod

=item chmod LIST

Functions as under Perl, with the difference that octal numbers are
represented differently (C<0o755> rather than C<0755>). You may also use
it as a method, e. g. C<$fh.chmod(0o755)>.

X<| chomp - perlfunc>
=head2 chomp

=item chomp VARIABLE

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

Note that C<chomp()> (without arguments) is not supported in Raku.

The Raku ecosystem has a module L<C<P5chomp>|https://modules.raku.org/dist/P5chomp>
which exports a C<chomp> function that mimics the original Perl behavior
as much as possible.

X<| chop - perlfunc>
=head2 chop

=item chop VARIABLE

As with C<chomp>, in Raku, this returns the chopped string, rather than
chopping in place. I. e. C<$x = "howdy";$y = chop($x);> results in C<$x>
being "howdy" and C<$y> being "howd". Also works as a method: C<$y = $x.chop>.

Note that C<chop()> (without arguments) is not supported in Raku.

The Raku ecosystem has a module L<C<P5chomp>|https://modules.raku.org/dist/P5chomp>
which exports a C<chop> function that mimics the original Perl behavior
as much as possible.

.head2 chown

=item chown LIST

C<chown> is not in Raku.

X<| chr - perlfunc>
=head2 chr

=item chr NUMBER

Similar to the Perl 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"

Note that C<chr()> (without arguments) is not supported in Raku.

The Raku ecosystem has a module L<C<P5chr>|https://modules.raku.org/dist/P5chr>
which exports a C<chr> function that mimics the original Perl behavior as
much as possible.

X<| chroot - perlfunc>
=head2 chroot

=item chroot FILENAME

C<chroot> is not in Raku.

X<| close - perlfunc>
=head2 close

=item close FILEHANDLE

As in Perl, closes a filehandle. Returns a Boolean value. Both C<close
$fh> and C<$fh.close> will work.

Note that C<close()> (without arguments) is not supported in Raku.

X<| closedir - perlfunc>
=head2 closedir

=item closedir DIRHANDLE

Not supported in Raku.

The Raku ecosystem has a module L<C<P5opendir>|https://modules.raku.org/dist/P5opendir>
which exports a C<closedir> function that mimics the original Perl behavior
as much as possible.

X<| connect - perlfunc>
=head2 connect

=item connect SOCKET, NAME

Use L<connect|/routine/connect> from L<IO::Socket::Async|/type/IO::Socket::Async> for
an asynchronous socket or create a L<IO::Socket::INET|/type/IO::Socket::INET> socket
for a synchronous one.

X<| continue - perlfunc>
=head2 continue

=item continue BLOCK

=item continue

Instead of a C<continue> block, you should use a C<NEXT> block. The
closest analog to a bare C<continue;> in Perl appears to be
C<proceed>/C<succeed>.

X<| cos - perlfunc>
=head2 cos

=item cos EXPR

Works as in Perl.

C<cos> also operates on C<$_> in the absence of a value, but not as a
function, and as a method you need to call it as C<.cos> rather than simply
C<cos>.

The Raku ecosystem has a module L<C<P5math>|https://modules.raku.org/dist/P5math>
which exports a C<cos> function that mimics the original Perl behavior as
much as possible.

X<| crypt - perlfunc>
=head2 crypt

=item crypt PLAINTEXT, SALT

Not available in Raku.

The Raku ecosystem has a module L<C<P5math>|https://modules.raku.org/dist/P5math>
which exports a C<crypt> function that mimics the original Perl behavior as
much as possible.

X<| dbm - perlfunc>
=head2 dbm functions

=item dbmclose HASH

=item dbmopen HASH, DBNAME, MASK

These functions have largely been superseded in Perl, and are unlikely to
ever turn up in Raku (although any assumptions about the Raku database
implementation may be premature).

X<| defined - perlfunc>
=head2 defined

=item defined EXPR

Probably does what you expect, but technically it returns C<False> on
the type object, and C<True> otherwise. This may make more sense when
you realize that C<$num.raku> is the type C<Any> if you haven't assigned
anything to it, and the assigned value if you have. Can, of course be
used as a method: C<$num.defined>.  And any newly created class can have
its own C<.defined> method, thereby deciding how and when it should be
considered undefined.

Note that C<defined()> (without arguments) is not supported in Raku.

The Raku ecosystem has a module L<C<P5defined>|https://modules.raku.org/dist/P5defined>
which exports a C<defined> function that mimics the original Perl behavior
as much as possible.

X<| delete - perlfunc>
=head2 delete

=item delete EXPR

Raku replaces this with the new adverb syntax, specifically the
C<:delete> adverb. E. g. C<my $deleted_value = %hash{$key}:delete;> and
C<my $deleted_value = @array[$i]:delete;>.

X<| die - perlfunc>
=head2 die

=item die LIST

Works similarly to the Perl version, but Raku's Exception mechanism
may give you more power and flexibility than is available in Perl.
See L<exceptions|/language/exceptions>. To omit the stacktrace
and location, like Perl's C<die "...\n">, use:

    note "...";
    exit 1;

X<| do - perlfunc>
=head2 do

=item do BLOCK

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

=item do EXPR

Has been replaced in Raku by C<EVALFILE>.

X<| dump - perlfunc>
=head2 dump

=item dump LABEL

According to S29, C<dump> has been... dumped.

X<| each - perlfunc>
=head2 each

=item each HASH

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

Incidentally, what we have there with the C<< -> >> 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.
L<https://design.raku.org/S04.html#The_for_statement> may be of some
help here, as well as the design document at
L<https://design.raku.org/S06.html#%22Pointy_blocks%22>. There is also
some information at L<https://en.wikibooks.org/wiki/Perl_6_Programming/Blocks_and_Closures#Pointy_Blocks>

The Raku ecosystem has a module L<C<P5each>|https://modules.raku.org/dist/P5each>
which exports an C<each> function that mimics the original Perl behavior
as much as possible.

X<| eof - perlfunc>
=head2 eof

=item eof FILEHANDLE

In Raku, this is not usable as a function, but only as a method. I. e.
C<$filehandle.eof>. Returns C<True> if at end of file.

X<| eval - perlfunc>
=head2 eval

=item eval EXPR

=item eval EXPR

The closest replacement is the L<EVAL|/routine/EVAL> function. However,
this function has to be allowed explicitly using a pragma to work in the
same way. Note that C<EVAL> does not do any L<exception
handling|/language/exceptions>!

X<| evalbytes - perlfunc>
=head2 evalbytes

=item evalbytes EXPR

No equivalent.

X<| exec - perlfunc>
=head2 exec

=item exec LIST

Nothing in Raku exactly replicates the Perl C<exec>. C<shell> and
C<run> are similar to Perl's C<system>, but C<exec>'s behavior of not
returning after executing a system command would have to be emulated by
something like C<shell($command);exit();> or possibly C<exit
shell($command);>.

Neither of these workarounds have the behavior (on Unix-like systems)
of I<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 C<exec>'s
function of returning stale resources to the operating system.

If you want C<exec> for these behaviors, you can use an C<exec*>
function via the C<NativeCall> interface. Consult your operating
system manual pages for C<exec> (or other similarly-named calls such
as C<execl>, C<execv>, C<execvp>, or C<execvpe>). (Beware: these calls
are not generally portable between Unix-like operating system
families.)  Given those caveats, the Raku ecosystem
L<C<Native::Exec>|https://modules.raku.org/dist/Native::Exec> module
exports an C<exec> function for Unix-like systems.

X<| exists - perlfunc>
=head2 exists

=item exists EXPR

In Raku, this is not a function, but an adverb:

=for code :preamble<no strict;>
%hash{$key}:exists;
@array[$i]:exists;

X<| exit - perlfunc>
=head2 exit

=item exit EXPR

Appears to do the same thing as in Perl.

X<| exp - perlfunc>
=head2 exp

=item exp EXPR

Same as in Perl.

C<exp> also operates on C<$_> in the absence of a value, but not as a
function, and as a method you need to call it as C<.exp> rather than simply
C<exp>.

The Raku ecosystem has a module L<C<P5math>|https://modules.raku.org/dist/P5math>
which exports an C<exp> function that mimics the original Perl behavior as
much as possible.

X<| fc - perlfunc>
=head2 fc

=item fc EXPR

Looks like it does the same thing as in Perl except that calling it without
arguments is not supported in Raku.

The Raku ecosystem has a module L<C<P5fc>|https://modules.raku.org/dist/P5fc>
which exports a C<fc> function that mimics the original Perl behavior as
much as possible.

X<| fcntl - perlfunc>
=head2 fcntl

=item fcntl FILEHANDLE, FUNCTION, SCALAR

Appears not to be in Raku.

X<| __FILE__ - perlfunc>
=head2 __FILE__

=item __FILE__

Replaced by C<$?FILE> which is slightly different from C<__FILE__> in that
it is always an absolute path, rather than a relative one in the Perl case.

The Raku ecosystem has a module L<C<P5__FILE__>|https://modules.raku.org/dist/P5__FILE__>
which exports a C<__FILE__> term that mimics the original Perl behavior as
much as possible.

X<| fileno - perlfunc>
=head2 fileno

=item fileno FILEHANDLE

The C<native-descriptor> method on C<IO::Handle> returns the equivalent of
C<fileno>.

The Raku ecosystem has a module L<C<P5fileno>|https://modules.raku.org/dist/P5fileno>
which exports a C<fileno> function that mimics the original Perl behavior
as much as possible.

X<| flock - perlfunc>
=head2 flock

=item flock FILEHANDLE, OPERATION

Currently unimplemented.

X<| fork - perlfunc>
=head2 fork

=item fork

There is no built-in C<fork> function. While it's possible to call it using
NativeCall, it's highly unlikely that the resulting process will be usable.

Raku provides extensive support for, and internally uses, threads. However,
C<fork> only clones the thread that called C<fork>, resulting in a process that
will be missing its other threads, which will have been in unknown states and
probably holding locks. Even if a Raku program doesn't knowingly start any
threads, the compiler may create some of its own in the process of precompilation,
and the VMs that Raku runs on also create their own internal worker threads for
doing things like optimization and GC in the background. Thus, the presence of
threads is pretty much assured, and there's no reasonable way to make C<fork>
reliably work in this case.

X<| formats - perlfunc>
=head2 formats

=item format

=item formline PICTURE, LIST

Raku does not have built-in formats.

X<| getc - perlfunc>
=head2 getc

=item getc FILEHANDLE

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

X<| getpeername - perlfunc>
=head2 getpeername

=item getpeername SOCKET

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

X<| getpgrp - perlfunc>
=head2 getpgrp

=item getpgrp PID

Will not be implemented.

The Raku ecosystem has a module L<C<P5getpriority>|https://modules.raku.org/dist/P5getpriority>
which exports a C<getpgrp> function that mimics the original Perl behavior
as much as possible.

X<| getppid - perlfunc>
=head2 getppid

=item getppid PID

Will not be implemented.

The Raku ecosystem has a module L<C<P5getpriority>|https://modules.raku.org/dist/P5getpriority>
which exports a C<getppid> function that mimics the original Perl behavior
as much as possible.

X<| getpriority - perlfunc>
=head2 getpriority

=item getpriority WHICH, WHO

Will not be implemented.

The Raku ecosystem has a module L<C<P5getpriority>|https://modules.raku.org/dist/P5getpriority>
which exports a C<getpriority> function that mimics the original Perl
behavior as much as possible.

X<| get and set - perlfunc>
=head2 get and set functions

=item endpwent

=item getlogin

=item getpwent

=item getpwnam NAME

=item getpwuid UID

=item setpwent

The Raku ecosystem has a module L<C<P5getpwnam>|https://modules.raku.org/dist/P5getpwnam>
which exports the C<endpwent>, C<getlogin>, C<getpwent>, C<getpwnam>,
C<getpwuid> and C<setpwent> functions that mimic the original Perl behavior
as much as possible.

=item endgrent

=item getgrent

=item getgrgid GID

=item getgrnam NAME

=item setgrent

The Raku ecosystem has a module L<C<P5getgrnam>|https://modules.raku.org/dist/P5getgrnam>
which exports the C<endgrent>, C<getgrent>, C<getgrgid>, C<getgrnam> and
C<setgrent> functions that mimic the original Perl behavior as much as
possible.

=item endnetent

=item getnetbyaddr ADDR, ADDRTYPE

=item getnetbyname NAME

=item getnetent

=item setnetent STAYOPEN

The Raku ecosystem has a module L<C<P5getnetbyname>|https://modules.raku.org/dist/P5getnetbyname>
which exports the C<endnetent>, C<getnetent>, C<getnetbyaddr>, C<getnetbyname>
and C<setnetent> functions that mimic the original Perl behavior as much as
possible.

=item endservent

=item getservbyname NAME, PROTO

=item getservbyport PORT, PROTO

=item getservent

=item setservent STAYOPEN

The Raku ecosystem has a module L<C<P5getservbyname>|https://modules.raku.org/dist/P5getservbyname>
which exports the C<endservent>, C<getservent>, C<getservbyname>,
C<getservbyport> and C<setservent> functions that mimic the original Perl
behavior as much as possible.

=item endprotoent

=item getprotobyname NAME

=item getprotobynumber NUMBER

=item getprotoent

=item setprotoent STAYOPEN

The Raku ecosystem has a module L<C<P5getprotobyname>|https://modules.raku.org/dist/P5getprotobyname>
which exports the C<endprotoent>, C<getprotoent>, C<getprotobyname>,
C<getprotobynumber> and C<setprotoent> functions that mimic the original
Perl behavior as much as possible.

=item gethostbyname NAME

=item gethostbyaddr ADDR, ADDRTYPE

=item gethostent

=item sethostent STAYOPEN

=item endhostent

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

X<| getsock - perlfunc>
=head2 getsock*

=item getsockname SOCKET

=item getsockopt SOCKET, LEVEL, OPTNAME

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

X<| glob - perlfunc>
=head2 glob

=item glob EXPR

Not available in core, although some of the functionality is offered by
L<dir|/routine/dir> routine and its C<test> argument.

See L«C<IO::Glob> module in ecosystem|https://modules.raku.org/dist/IO::Glob»

X<| gmtime - perlfunc>
=head2 gmtime

=item gmtime EXPR

Like the various parts of C<localtime>, C<gmtime>'s functionality
appears to in the C<DateTime> object. To get a UTC version of a
C<DateTime> object for the current time, for instance, use C<my $gmtime
= DateTime.now.utc>.

The Raku ecosystem has a module L<C<P5localtime>|https://modules.raku.org/dist/P5localtime>
which exports a C<gmtime> function that mimics the original Perl behavior
as much as possible.

X<| goto - perlfunc>
=head2 goto

=item goto LABEL

=item goto EXPR

=item goto &NAME

The syntax for C<goto LABEL> is already accepted, but the runtime part of
C<goto> is not yet implemented.  So this will result in a runtime error:

    FOO: goto FOO; # Label.goto() not yet implemented. Sorry.

X<| grep - perlfunc>
=head2 grep

=item grep BLOCK LIST

=item grep EXPR, LIST

Still in Raku, with the caveat that the block form now requires a
comma after the block. I.e. C<@foo = grep { $_ = "bars" }, @baz>. Can
also be used as a method: C<@foo = @bar.grep(/^f/)>

X<| hex - perlfunc>
=head2 hex

=item hex EXPR

In Raku an expression B<must> be specified.

Replaced by the adverbial form C<:16>. E. g. C<:16("aF")> returns 175. This is
Str->Int.

The opposite result can be achieved (Int->Str) by using the C<.base> method:
C<0xaF.base(10)>

It just so happens that C<.Str> defaults to base 10, so if you just C<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.

The Raku ecosystem has a module L<C<P5hex>|https://modules.raku.org/dist/P5hex>
which exports a C<hex> function that mimics the original Perl behavior as
much as possible.

X<| import - perlfunc>
=head2 import

=item import LIST

Was never a builtin function in Perl in the first place. In Raku,
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
L<this section|/language/5to6-nutshell#Importing_specific_functions_from_a_module>.

X<| index - perlfunc>
=head2 index

=item index STR, SUBSTR, POSITION

Works as in Perl. Can also now be used as a method:
C<"howdy!".index("how"); # 0>.  Main difference with Perl is that C<Nil> is
returned instead of C<-1> when the substring is not found.  This is very
useful in combination with the C<with> command:

    with index("foo","o") -> $index {
        say "Found it at $index";
    }
    else {
        say "Not found"
    }

The Raku ecosystem has a module L<C<P5index>|https://modules.raku.org/dist/P5index>
which exports an C<index> function that mimics the original Perl behavior
as much as possible.

X<| int - perlfunc>
=head2 int

=item int EXPR

There is a C<truncate> function in Raku (also usable as a method) that
does what Perl's C<int> does. You may want to use that as a direct
translation of Perl code, but in Raku, you can just as easily call
the C<.Int> method on the number. C<3.9.Int; # 3> and C<3.9.truncate>
are equivalent.

Please note that C<int> B<does> have a meaning in Raku.  It is type that
can be used to indicate a native integer:

    my int $a = 42;   # a native integer, similar to Perl's integer values

C<int> also operates on C<$_> in the absence of a value, but not as a
function, and as a method you need to call it as C<.int> rather than simply
C<int>.

The Raku ecosystem has a module L<C<P5math>|https://modules.raku.org/dist/P5math>
which exports an C<int> function that mimics the original Perl behavior as
much as possible.

X<| ioctl - perlfunc>
=head2 ioctl

=item ioctl FILEHANDLE, FUNCTION, SCALAR

Currently unimplemented in Raku.

X<| join - perlfunc>
=head2 join

=item join EXPR, LIST

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

X<| keys - perlfunc>
=head2 keys

=item keys HASH

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

X<| kill - perlfunc>
=head2 kill

=item kill SIGNAL, LIST

=item kill SIGNAL

No pre-defined core alternative exists. A non-portable method can be to use
L<NativeCall|/language/nativecall>:

    use NativeCall;
    sub kill(int32, int32) is native {*};
    kill $*PID, 9; # OUTPUT: «Killed␤»

To kill processes that were started by creating a L<Proc::Async|/type/Proc::Async>, use
L«C<Proc::Async.kill> method|/type/Proc::Async#method_kill».

X<| last - perlfunc>
=head2 last

=item last LABEL

=item last EXPR

=item last

Same as in Perl.

X<| lc - perlfunc>
=head2 lc

=item lc EXPR

Works as in Perl, and also as a method: C<"UGH".lc>.  In Raku an
expression B<must> be specified.

The Raku ecosystem has a module L<C<P5lc>|https://modules.raku.org/dist/P5lc>
which exports an C<lc> function that mimics the original Perl behavior as
much as possible.

X<| lcfirst - perlfunc>
=head2 lcfirst

=item lcfirst EXPR

Does not exist in Raku.

The Raku ecosystem has a module L<C<P5lcfirst>|https://modules.raku.org/dist/P5lcfirst>
which exports an C<lcfirst> function that mimics the original Perl behavior
as much as possible.

X<| length - perlfunc>
=head2 length

=item length EXPR

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

The Raku ecosystem has a module L<C<P5length>|https://modules.raku.org/dist/P5length>
which exports an C<length> function that mimics the original Perl behavior
as much as possible.

X<| __LINE__ - perlfunc>
=head2 __LINE__

=item __LINE__

Replaced by C<$?LINE>.

The Raku ecosystem has a module L<C<P5__FILE__>|https://modules.raku.org/dist/P5__FILE__>
which exports a C<__LINE__> term that mimics the original Perl behavior as
much as possible.

X<| link - perlfunc>
=head2 link

=item link OLDFILE, NEWFILE

See L<link|/routine/link>

X<| listen - perlfunc>
=head2 listen

=item listen SOCKET, QUEUESIZE

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

X<| local - perlfunc>
=head2 local

=item local EXPR

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

X<| localtime - perlfunc>
=head2 localtime

=item localtime EXPR

Most of the functionality of C<localtime> is found in C<DateTime>. The
specific parts of C<localtime> can be found as follows:

=begin code

my $d = DateTime.now;
my $sec  = $d.second; # Potentially includes fractional seconds
my $min  = $d.minute;
my $hour = $d.hour;
my $mday = $d.day-of-month; # or $d.day; 1..31
my $mon  = $d.month; # 1..12
my $year = $d.year;
my $wday = $d.day-of-week; # 1 => Monday, 2 => Tuesday, etc.
my $yday = $d.day-of-year; # 1..366
=end code

Please note that ranges are not 0-based in Raku, as shown in the
comments in the example.

There does not currently appear to be a way to get Perl's
C<$isdst>. Also, the result of C<scalar(localtime)> that Perl
provides is not available. C<$d.Str> will give something along the
lines of "2015-06-29T12:49:31-04:00".

The Raku ecosystem has a module L<C<P5localtime>|https://modules.raku.org/dist/P5localtime> which exports a C<localtime> function that mimics the original
Perl behavior as much as possible.

X<| lock - perlfunc>
=head2 lock

=item lock THING

There currently is no equivalent for this In Raku.  There is a C<Lock>
class for creating a Lock object, that can be locked/unlocked as needed.
But such a lock does not refer to any external objects.

X<| log - perlfunc>
=head2 log

=item log EXPR

Same as in Perl.

C<log> also operates on C<$_> in the absence of a value, but not as a
function, and as a method you need to call it as C<.log> rather than simply
C<log>.

The Raku ecosystem has a module L<C<P5math>|https://modules.raku.org/dist/P5math>
which exports a C<log> function that mimics the original Perl behavior as
much as possible.

X<| lstat - perlfunc>
=head2 lstat

=item lstat FILEHANDLE

=item lstat EXPR

=item lstat DIRHANDLE

=item lstat

Likely implemented somewhere in one of the C<IO> classes in Raku, but
it is not clear where at this time.

X<| m// - perlfunc>
=head2 m//

=item m//

Regular expression syntax is somewhat different in Raku, but the match
operator still exists. If you're trying to rewrite some Perl code, the
most important difference is that C<=~> is replaced by the smartmatch
operator, C<~~>. Similarly, C<!~> is replaced by C<!~~>. Options for
regex operators are adverbs and are complicated. For details, see
L<Adverbs|/language/regexes#Adverbs>

X<| map - perlfunc>
=head2 map

=item map BLOCK LIST

=item map EXPR, LIST

As a function, the only difference between Perl and Raku is that, if
you're using a block, the block must be followed by a comma. Can also be
used as a method: C<@new = @old.map: { $_ * 2 }>

X<| mkdir - perlfunc>
=head2 mkdir

=item mkdir FILENAME, MASK

=item mkdir FILENAME

Works as in Perl.  When giving a multi-level directory specification,
it will automatically create non-existing intermediate directories with
the same MASK (similar to what "make_path" does of the File::Path module
in Perl).

=item mkdir

The zero argument (implicit C<$_>) version is not permitted in Raku.

X<| msg* - perlfunc>
=head2 msg*

=item msgctl ID, CMD, ARG

=item msgget KEY, FLAGS

=item msgrcv ID, VAR, SIZE, TYPE, FLAGS

=item msgsnd ID, MSG, FLAGS

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

X<| my - perlfunc>
=head2 my

=item my VARLIST

=item my TYPE VARLIST

=item my VARLIST : ATTRS

=item my TYPE VARLIST : ATTRS

Works as in Perl.

X<| next - perlfunc>
=head2 next

=item next LABEL

=item next EXPR

=item next

The same in Raku.

X<| no - perlfunc>
=head2 no

=item no MODULE VERSION

=item no MODULE LIST

=item no MODULE

=item no VERSION

In Raku, this is usable for pragmas such as C<strict>, but not for
modules or versions.

X<| oct - perlfunc>
=head2 oct

=item oct

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

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

The Raku ecosystem has a module L<C<P5hex>|https://modules.raku.org/dist/P5hex>
which exports an C<oct> function that mimics the original Perl behavior as
much as possible.

X<| open - perlfunc>
=head2 open

=item open FILEHANDLE, EXPR

=item open FILEHANDLE, MODE, EXPR

=item open FILEHANDLE, MODE, EXPR, LIST

=item open FILEHANDLE, MODE, REFERENCE

=item open FILEHANDLE

The most obvious change from Perl is the file mode syntax. To open a
file for reading only, you would say C<open("file", :r)>. For write-
only, read-write, and append, you would use C<:w>, C<:rw>, and C<:a>
respectively. There are also options for encoding and how the filehandle
deals with newlines. Details L<here|/routine/open>.

Another important change is that filehandles don't get automatically closed on scope exit. It's necessary to call L<close|/routine/close> explicitly.

X<| opendir - perlfunc>
=head2 opendir

=item opendir DIRHANDLE, EXPR

No replacement. See L«C<&dir>/C<IO::Path.dir>|/routine/dir» for alternatives.

The Raku ecosystem has a module L<C<P5opendir>|https://modules.raku.org/dist/P5opendir>
which exports an C<opendir> function that mimics the original Perl behavior
as much as possible.

X<| ord - perlfunc>
=head2 ord

=item ord EXPR

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

Note that C<ord()> (without arguments) is not supported in Raku.

The Raku ecosystem has a module L<C<P5chr>|https://modules.raku.org/dist/P5chr>
which exports a C<ord> function that mimics the original Perl behavior as
much as possible.

X<| our - perlfunc>
=head2 our

=item our VARLIST

=item our TYPE VARLIST

=item our VARLIST : ATTRS

=item our TYPE VARLIST : ATTRS

The same in Raku.

X<| pack - perlfunc>
=head2 pack

=item pack TEMPLATE, LIST

Available in Raku when C<use experimental :pack> has been specified in the
scope where C<pack> needs to be called. The template options are currently
more restricted than they are in Perl. The current documented list can be
found at L<unpack|/routine/unpack>.

The Raku ecosystem has a module L<C<P5pack>|https://modules.raku.org/dist/P5pack>
which exports a C<pack> function that mimics the original Perl behavior as
much as possible and which has a bigger set of supported features than the
experimental Raku version.

X<| package - perlfunc>
=head2 package

=item package NAMESPACE

=item package NAMESPACE VERSION

=item package NAMESPACE BLOCK

=item package NAMESPACE VERSION BLOCK

S10 indicates that C<package> can be used in Raku, but only with a
block. I. e. C<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 C<package Foo;> as the first statement in a file indicates that
the rest of the file is Perl code, but the usefulness of this is
unclear. In fact, as modules and classes are declared with distinct
keywords (such as C<class>), it's unlikely you will use C<package>
directly in Raku.

X<| __PACKAGE__ - perlfunc>
=head2 __PACKAGE__

=item __PACKAGE__

Replaced by C<$?PACKAGE> which is slightly different from C<__PACKAGE__> in
that it is the actual package object.  You should call the C<.^name> method
on it to get a string.

The Raku ecosystem has a module L<C<P5__FILE__>|https://modules.raku.org/dist/P5__FILE__>
which exports a C<__PACKAGE__> term that mimics the original Perl behavior
as much as possible.

X<| pipe - perlfunc>
=head2 pipe

=item pipe READHANDLE, WRITEHANDLE

Depending on your needs, see L«C<Channel>|/type/Channel» to shuttle
data between threads (and L<Concurrency tutorial|/language/concurrency>
for other options), or see L«C<Proc>|/type/Proc» type for piping to
and from processes.

X<| pop - perlfunc>
=head2 pop

=item pop ARRAY

Works in Raku, and can also be used as a method. I. e. C<my $x = pop
@a;> and C<my $x = @a.pop;> are equivalent.

The non-parameter version of C<pop> does not exist.  Also, if the array
is empty, a Failure will be returned in Raku, which will throw if the
value is actually used in a significant way.

If you are using only defined values in your array, you can use the C<with>
function to handle this case:

=for code :preamble<my @array;>
with pop @array -> $popped {
    say "popped '$popped' of the array";
}
else {
    say "there was nothing to pop";
}

The Raku ecosystem has a module L<C<P5push>|https://modules.raku.org/dist/P5push>
which exports a C<pop> function that mimics the original Perl behavior as
much as possible.

X<| pos - perlfunc>
=head2 pos

=item pos SCALAR

Not available in Raku. The closest equivalent is the C<:c> adverb,
which defaults to C<$/.to> if C<$/> is true, and C<0> if it isn't. For
information on C<:c>, see
L<Continue|/language/regexes#Continue>.

X<| print - perlfunc>
=head2 print

=item print FILEHANDLE LIST

=item print FILEHANDLE

=item print LIST

=item print

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

The Raku ecosystem has a module L<C<P5print>|https://modules.raku.org/dist/P5print>
which exports a C<print> function that mimics the original Perl behavior
as much as possible.

X<| printf - perlfunc>
=head2 printf

=item printf FORMAT, LIST

=item printf

Raku version is similar; see
L<sprintf|/routine/sprintf> for details
on acceptable format directives. To print to a filehandle other than
STDOUT, use the L«C<.printf>|/routine/printf» method on that filehandle.

The Raku ecosystem has a module L<C<P5print>|https://modules.raku.org/dist/P5print>
which exports a C<printf> function that mimics the original Perl behavior
as much as possible.

X<| prototype - perlfunc>
=head2 prototype

=item prototype FUNCTION

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

X<| push - perlfunc>
=head2 push

=item push ARRAY, LIST

Works as in Perl, as well as being available as a method:
C<@a.push("foo");>. I<Note:> the flattening behavior is different in Raku:
C<@b.push: @a> will push C<@a> into C<@b> as a single element. See also the
L<append method|/type/Array#method_append>.

Also note that C<push> in Raku returns the array to which was pushed,
contrary to Perl where it returns the new number of elements.

The Raku ecosystem has a module L<C<P5push>|https://modules.raku.org/dist/P5push>
which exports a C<push> function that mimics the original Perl behavior as
much as possible.

X<| quoting - perlfunc>
=head2 quoting

=item q/STRING/

=item qq/STRING/

=item qw/STRING/

=item qx/STRING/

These survive the transition to Raku. Some notes:

=for code :lang<perl>
q/.../;  # is still equivalent to using single quotes.
qq/.../; # is still equivalent to using double quotes.
qw/.../; # is more commonly rendered as C<< <...> >> in Raku.

There are some added quoting constructs and equivalents, as explained at
L<quoting|/language/quoting>.

=item qr/STRING/
X<|qr (Perl)>

Has been replaced by C<rx/.../>.

=item 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
C<$foo> will treat C<$foo> as a literal string, and using C<< <$foo> >>
will interpret the contents of C<$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
L<https://design.raku.org/S05.html#Extensible_metasyntax_(%3C...%3E)>

The Raku ecosystem has a module L<C<P5quotemeta>|https://modules.raku.org/dist/P5quotemeta>
which exports a C<quotemeta> function that mimics the original Perl
behavior as much as possible.

X<| rand - perlfunc>
=head2 rand

=item rand EXPR

C<rand> by itself works as it does in Perl, 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 C<rand(100)> is equivalent to
C<100.rand> in Raku. Additionally, you can get a random integer by
using something like C<(^100).pick>. For I<why> you are able to do that,
see L<^ operator|/language/operators#prefix_%5E> and
L<pick|/routine/pick>.

The Raku ecosystem has a module L<C<P5math>|https://modules.raku.org/dist/P5math>
which exports a C<rand> function that mimics the original Perl behavior as
much as possible.

X<| read - perlfunc>
=head2 read

=item read FILEHANDLE, SCALAR, LENGTH, OFFSET

C<read> is found in C<IO::Handle> and C<IO::Socket> in Raku. It reads
the specified number of bytes (rather than characters) from the relevant
handle or socket. The use of an offset available in Perl is not
documented to exist at this time.

X<| readdir - perlfunc>
=head2 readdir

=item readdir DIRHANDLE

Not a builtin function. To iterate through the contents of a directory,
take a look at L<dir routine|/type/IO::Path#routine_dir>.

The Raku ecosystem has a module L<C<P5opendir>|https://modules.raku.org/dist/P5opendir>
which exports a C<readdir> function that mimics the original Perl behavior
as much as possible.

X<| readline - perlfunc>
=head2 readline

=item readline

Not available in Raku. You most likely want to use the C<.lines>
method in some way. For more detailed information on reading from files,
see L<io|/language/io>.

X<| readlink - perlfunc>
=head2 readlink

=item readlink EXPR

Appears to be gone from Raku.  There B<is> a method C<resolve> in
C<IO::Path> that will follow symlinks if the OS / Filesystem supports them.

The Raku ecosystem has a module L<C<P5readlink>|https://modules.raku.org/dist/P5readlink>
which exports a C<readlink> function that mimics the original Perl behavior
as much as possible.

X<| readpipe - perlfunc>
=head2 readpipe

=item readpipe EXPR

=item readpipe

Doesn't appear to be working in Raku, but C<qx//> is functional, so it might
be lurking around in some class that isn't obvious.

X<| recv - perlfunc>
=head2 recv

=item recv SOCKET, SCALAR, LENGTH, FLAGS

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

X<| redo - perlfunc>
=head2 redo

=item redo LABEL

=item redo EXPR

=item redo

Unchanged in Raku.

X<| ref - perlfunc>
=head2 ref

=item ref EXPR

Gone. To quote S29, "If you really want the type name, you can
use C<$var.WHAT.^name>.

The Raku ecosystem has a module L<C<P5ref>|https://modules.raku.org/dist/P5ref>
which exports a C<ref> function that mimics the original Perl behavior as
much as possible.

X<| rename - perlfunc>
=head2 rename

=item rename OLDNAME, NEWNAME

Still available in Raku.

X<| requires - perlfunc>
=head2 requires

=item require VERSION

No equivalent.

X<| reset - perlfunc>
=head2 reset

=item reset EXPR

No equivalent.

The Raku ecosystem has a module L<C<P5reset>|https://modules.raku.org/dist/P5reset>
which exports a C<reset> function that mimics the original Perl behavior as
much as possible.

X<| return - perlfunc>
=head2 return

=item return EXPR

Appears to be available in Raku, although not clearly documented.

X<| reverse - perlfunc>
=head2 reverse

=item reverse LIST

In Raku, this only reverses the elements of a list. C<reverse(@a)>
or C<@a.reverse>. To reverse the characters in a string, use the
C<.flip> method.

C<reverse> without parameters is not supported in Raku.

The Raku ecosystem has a module L<C<P5reverse>|https://modules.raku.org/dist/P5reverse>
which exports a C<reverse> function that mimics the original Perl behavior
as much as possible.

X<| rewinddir - perlfunc>
=head2 rewinddir

=item rewinddir DIRHANDLE

Not supported in Raku.

The Raku ecosystem has a module L<C<P5rewinddir>|https://modules.raku.org/dist/P5rewinddir>
which exports a C<rewinddir> function that mimics the original Perl
behavior as much as possible.

X<| rindex - perlfunc>
=head2 rindex

=item rindex STR, SUBSTR, POSITION

Works as in Perl, and may also be used as a method. E. g. C<$x =
"babaganush";say $x.rindex("a"); say $x.rindex("a", 3); # 5, 3>.  Main
difference with Perl is that C<Nil> is returned instead of C<-1> when
the substring is not found.  This is very useful in combination with the
C<with> command:

    with index("foo","o") -> $index {
        say "Found it at $index";
    }
    else {
        say "Not found"
    }

The Raku ecosystem has a module L<C<P5index>|https://modules.raku.org/dist/P5index>
which exports a C<rindex> function that mimics the original Perl behavior
as much as possible.

X<| rmdir - perlfunc>
=head2 rmdir

=item rmdir FILENAME

Works in Raku and can also be used as a method. C<rmdir "Foo";> and
C<"Foo".IO.rmdir;> are equivalent.

X<| s/// - perlfunc>
=head2 s///

=item s///

Regular expression syntax is somewhat different in Raku, but the
substitution operator exists. If you're trying to rewrite some
Perl code, the most important difference is that C<=~> is replaced
by the smartmatch operator, C<~~>. Similarly, C<!~> is C<!~~>.
Options for regex operators are adverbs and are complicated. For
details, see L<Adverbs page|/language/regexes#Adverbs>

X<| say - perlfunc>
=head2 say

=item say FILEHANDLE

=item say LIST

=item say

C<say> can be used as a function, defaulting to standard out. To use
C<say> as a function with a filehandle I<instead> of standard out, you
need to put a colon after the filehandle. I. e. C<say $fh: "Howdy!">.
The use of the colon as an "invocant marker" here is discussed at
L<https://design.raku.org/S03.html#line_4019>. Alternately, you can use
a method call: C<$fh.say("howdy!")>

The Raku ecosystem has a module L<C<P5print>|https://modules.raku.org/dist/P5print>
which exports a C<say> function that mimics the original Perl behavior as
much as possible.

X<| scalar - perlfunc>
=head2 scalar

=item scalar EXPR

Gone. Apparently "very" gone.

Some functions of the modules created for the CPAN Butterfly Plan accept
a C<:scalar> named parameter to indicate that the C<scalar> behavior of
the function is required.

X<| seek - perlfunc>
=head2 seek

=item seek FILEHANDLE, POSITION, WHENCE

Not documented in any real way yet, but listed as a method of the
C<IO::Handle> class.

The Raku ecosystem has a module L<C<P5seek>|https://modules.raku.org/dist/P5seek>
which exports a C<seek> function that mimics the original Perl behavior
as much as possible.

X<| seekdir - perlfunc>
=head2 seekdir

=item seekdir DIRHANDLE, POS

Not supported in Raku.

The Raku ecosystem has a module L<C<P5opendir>|https://modules.raku.org/dist/P5opendir>
which exports a C<seekdir> function that mimics the original Perl behavior
as much as possible.

X<| select - perlfunc>
=head2 select

=item select FILEHANDLE

"[S]elect as a global concept is dead." When I asked around about C<select>, I
was told that $*OUT and such are overridable in dynamic scope, and that
C<IO::Capture::Simple> (at L<https://github.com/sergot/IO-Capture-Simple>) may
be of use for something you might be doing with the value of C<select>.

=head2 semctl

=item semctl ID, SEMNUM, CMD, ARG

No longer in core.

X<| semget - perlfunc>
=head2 semget

=item semget KEY, NSEMS, FLAGS

No longer in core.

X<| semop - perlfunc>
=head2 semop

=item semop KEY, OPSTRING

No longer in core.

X<| send - perlfunc>
=head2 send

=item send SOCKET, MSG, FLAGS, TO

Can be found in the C<IO::Socket> class.

X<| setpgrp - perlfunc>
=head2 setpgrp

=item setpgrp PID, PGRP

Will not be implemented.

The Raku ecosystem has a module L<C<P5getpriority>|https://modules.raku.org/dist/P5getpriority>
which exports a C<setpgrp> function that mimics the original Perl behavior
as much as possible.

X<| setpriority - perlfunc>
=head2 setpriority

=item setpriority WHICH, WHO, PRIORITY

Will not be implemented.

The Raku ecosystem has a module L<C<P5getpriority>|https://modules.raku.org/dist/P5getpriority>
which exports a C<setpriority> function that mimics the original Perl
behavior as much as possible.

X<| setsockopt - perlfunc>
=head2 setsockopt

=item setsockopt SOCKET, LEVEL, OPTNAME, OPTVAL

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

X<| shift - perlfunc>
=head2 shift

=item shift ARRAY

=item shift EXPR

=item shift

Works in Raku, and can also be used as a method. I. e. C<my $x = shift
@a;> and C<my $x = @a.shift;> are equivalent.

The non-parameter version of C<shift> does not exist.  Also, if the array
is empty, a Failure will be returned in Raku, which will throw if the
value is actually used in a significant way.

If you are using only defined values in your array, you can use the C<with>
function to handle this case:

=for code :preamble<my @array;>
with shift @array -> $shifted {
    say "shifted '$shifted' of the array";
}
else {
    say "there was nothing to shift";
}

The Raku ecosystem has a module L<C<P5shift>|https://modules.raku.org/dist/P5shift>
which exports a C<shift> function that mimics the original Perl behavior
as much as possible.

X<| shm* - perlfunc>
=head2 shm*

=item shmctl ID, CMD, ARG

=item shmget KEY, SIZE, FLAGS

=item shmread ID, VAR, POS, SIZE

=item shmwrite ID, STRING, POS, SIZE

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

X<| shutdown - perlfunc>
=head2 shutdown

=item shutdown SOCKET, HOW

Not documented, but likely moved into C<IO::Socket>.

X<| sin - perlfunc>
=head2 sin

=item sin EXPR

Same as in Perl.

C<sin> also operates on C<$_> in the absence of a value, but not as a
function, and as a method you need to call it as C<.sin> rather than simply
C<sin>.

The Raku ecosystem has a module L<C<P5math>|https://modules.raku.org/dist/P5math>
which exports a C<sin> function that mimics the original Perl behavior as
much as possible.

X<| sleep - perlfunc>
=head2 sleep

=item sleep EXPR

Still works as in Perl, 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 Raku (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 Raku ecosystem has a module L<C<P5sleep>|https://modules.raku.org/dist/P5sleep>
which exports a C<sleep> function that mimics the original Perl behavior
as much as possible.

X<| sockets - perlfunc>
=head2 sockets

=item socket SOCKET, DOMAIN, TYPE, PROTOCOL

=item socketpair SOCKET1, SOCKET2, DOMAIN, TYPE, PROTOCOL

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

X<| sort - perlfunc>
=head2 sort

=item sort SUBNAME LIST

C<sort> exists in Raku, but is somewhat different. C<$a> and C<$b> are
no longer special (see L<Special Variables|/language/5to6-perlvar>) and sort routines no
longer return positive integers, negative integers, or 0, but rather
C<Order::Less>, C<Order::Same>, or C<Order::More> objects. See
L<sort|/routine/sort> for details. May also be used as a
method I. e. C<sort(@a)> is equivalent to C<@a.sort>.

X<| splice - perlfunc>
=head2 splice

=item splice ARRAY, OFFSET, LENGTH

=item splice ARRAY, OFFSET

=item splice ARRAY

=item splice EXPR, OFFSET, LENGTH, LIST

=item splice EXPR, OFFSET, LENGTH

=item splice EXPR, OFFSET

=item splice EXPR

Available in Raku. Can also be used as a method. C<< splice(@foo, 2, 3,
<M N O P>); >> is equivalent to C<< @foo.splice(2, 3, <M N O P>); >>.

X<| split - perlfunc>
=head2 split

=item split /PATTERN/, EXPR, LIMIT

=item split /PATTERN/, EXPR

=item split /PATTERN/

Works mostly as in Perl. 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
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 C<:all>, like this: C<split(';', "a;b;c",
:all) # a ; b ; c> Empty chunks are not removed from the result list as
they are in Perl. For that behavior, see C<comb>. Details on C<split>
are L<here|/routine/split>. Unsurprisingly, C<split>
also now works as a method: C<"a;b;c".split(';')>

=item split

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

X<| sprintf - perlfunc>
=head2 sprintf

=item sprintf FORMAT, LIST

Works as in Perl. The formats currently available are:

=table
    %   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:

=table
    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 (non-)compatibility:

=table
    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:

=table
    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)

X<| sqrt - perlfunc>
=head2 sqrt

=item sqrt EXPR

Same as in Perl.

C<sqrt> also operates on C<$_> in the absence of a value, but not as a
function, and as a method you need to call it as C<.sqrt> rather than simply
C<sqrt>.

The Raku ecosystem has a module L<C<P5math>|https://modules.raku.org/dist/P5math>
which exports a C<sqrt> function that mimics the original Perl behavior as
much as possible.

X<| srand - perlfunc>
=head2 srand

=item srand EXPR

Available in Raku.

=head2 stat

=item stat EXPR

=item stat DIRHANDLE

=item stat

Unlikely to be implemented as a built in function since it's POSIX specific,
but available through the C<NativeCall> interface.

X<| state - perlfunc>
=head2 state

=item state VARLIST

=item state TYPE VARLIST

=item state VARLIST : ATTRS

=item state TYPE VARLIST : ATTRS

Available in Raku, see L<state|/syntax/state>.

X<| study - perlfunc>
=head2 study

=item study SCALAR

=item study

C<study> is no more.

The Raku ecosystem has a module L<C<P5study>|https://modules.raku.org/dist/P5study>
which exports a C<study> function that mimics the original Perl behavior
as much as possible.

X<| sub - perlfunc>
=head2 sub

=item sub NAME BLOCK

=item sub NAME(PROTO) BLOCK

=item sub NAME : ATTRS BLOCK

=item 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),
C<@_> 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 to
Raku (although you should probably consider the option of using a
signature). For all the gory details, see
L<functions|/language/functions>.

X<| __SUB__ - perlfunc>
=head2 __SUB__

=item __SUB__

Replaced by C<&?ROUTINE> which is slightly different from C<__SUB__> in
that it is the actual C<Sub> (or C<Method>) object.  You should call the
C<.name> method on it to get a string.

The Raku ecosystem has a module L<C<P5__FILE__>|https://modules.raku.org/dist/P5__FILE__>
which exports a C<__SUB__> term that mimics the original Perl behavior
as much as possible.

X<| substr - perlfunc>
=head2 substr

=item substr EXPR, OFFSET, LENGTH, REPLACEMENT

See L<substr-rw|/routine/substr-rw>.

Can be used as a function or a method. Can't be used
on C<Str> literals, as they are immutable.

=begin code
    my $a = 'Cheesy';
    $a.substr-rw(4,1)="k"; # returns 'k'
    say $a; # OUTPUT: «Cheeky␤»

    substr-rw($a, 0, 3) = "Lea";
    say $a; # OUTPUT: «Leaky␤»
=end code

=item substr EXPR, OFFSET, LENGTH

=item substr EXPR, OFFSET

See L<substr|/routine/substr>.

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

X<| symlink - perlfunc>
=head2 symlink

=item symlink OLDFILE, NEWFILE

See L<symlink|/routine/symlink>.

X<| syscall - perlfunc>
=head2 syscall

=item syscall NUMBER, LIST

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

X<| sys* - perlfunc>
=head2 sys*

=item sysopen FILEHANDLE, FILENAME, MODE

=item sysopen FILEHANDLE, FILENAME, MODE, PERMS

=item sysread FILEHANDLE, SCALAR, LENGTH, OFFSET

=item sysread FILEHANDLE, SCALAR, LENGTH

=item sysseek FILEHANDLE, POSITION, WHENCE

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

X<| system - perlfunc>
=head2 system

=item system LIST

=item system PROGRAM LIST

For this, you probably want (L<run|/routine/run>)
or (L<shell routine|/routine/shell>).

X<| syswrite - perlfunc>
=head2 syswrite

=item syswrite FILEHANDLE, SCALAR, LENGTH, OFFSET

=item syswrite FILEHANDLE, SCALAR, LENGTH

=item syswrite FILEHANDLE, SCALAR

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

X<| tell - perlfunc>
=head2 tell

=item tell FILEHANDLE

As a method on C<IO::Handle>.

X<| telldir - perlfunc>
=head2 telldir

=item telldir DIRHANDLE

Not supported in Raku.

The Raku ecosystem has a module L<C<P5opendir>|https://modules.raku.org/dist/P5opendir>
which exports a C<telldir> function that mimics the original Perl behavior
as much as possible.

X<| tie - perlfunc>
=head2 tie

=item tie VARIABLE, CLASSNAME, LIST

=item tied VARIABLE

The Raku alternative to tying 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.  These are documented in
the C<Subscripts> section.

The Raku ecosystem has a module L<C<P5tie>|https://modules.raku.org/dist/P5tie>
which exports C<tie> / C<tied> functions that mimics the original Perl
behavior as much as possible.

X<| time - perlfunc>
=head2 time

=item time

Number of seconds since epoch (as an C<Int>), same as in Perl.

X<| times - perlfunc>
=head2 times

=item times

Not available in Raku.

The Raku ecosystem has a module L<C<P5times>|https://modules.raku.org/dist/P5times>
which exports a C<times> function that mimics the original Perl behavior
as much as possible.

X<| tr/// - perlfunc>
=head2 tr///

=item tr///

Works similarly to how it does in Perl. 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 Raku, C<tr///> has a method version,
called L<trans|/routine/trans>, which offers a few additional features.

Perl's C</r> flag is instead implemented as C<TR///> operator.
The C<y///> equivalent does not exist.

X<| truncate - perlfunc>
=head2 truncate

=item truncate FILEHANDLE, LENGTH

=item truncate EXPR, LENGTH

Not currently implemented (2018.04).

X<| uc - perlfunc>
=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 Raku ecosystem has a module L<C<P5lc>|https://modules.raku.org/dist/P5lc>
which exports a C<uc> function that mimics the original Perl behavior as
much as possible.

X<| ucfirst - perlfunc>
=head2 ucfirst

=item ucfirst EXPR

=item ucfirst

Raku has done away with C<ucfirst>. The title case function
L<C<tc>|/routine/tc> probably does what you need.

The Raku ecosystem has a module L<C<P5lcfirst>|https://modules.raku.org/dist/P5lcfirst>
which exports a C<ucfirst> function that mimics the original Perl behavior
as much as possible.

X<| undef - perlfunc>
=head2 undef

=item undef EXPR

There is no C<undef> in Raku. 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 Raku instead of discarding
the first result of C<caller>. C<caller> has been replaced by C<callframe> in
Raku, so the equivalent statement would be C<($file, $line) =
callframe.annotations<file line>;>

The Raku ecosystem has a module L<C<P5defined>|https://modules.raku.org/dist/P5defined>
which exports an C<undef> function that mimics the original Perl behavior
as much as possible.

=for comment
Add a note here about Type-based undefined values.

X<| unlink - perlfunc>
=head2 unlink

=item unlink LIST

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

=item unlink

The zero argument (implicit C<$_>) version of unlink is not available in Raku.

X<| unpack - perlfunc>
=head2 unpack

=item unpack TEMPLATE, EXPR

=item unpack TEMPLATE

Available in Raku 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. The current documented list can be
found at L<unpack|/routine/unpack>.

The Raku ecosystem has a module L<C<P5pack>|https://modules.raku.org/dist/P5pack>
which exports an C<unpack> function that mimics the original Perl behavior
as much as possible and which has a bigger set of supported features than the
experimental Raku version.

X<| unshift - perlfunc>
=head2 unshift

=item unshift ARRAY, LIST

=item unshift EXPR, LIST

Works as in Perl, as well as being available as a method:
C<@a.unshift("foo");>. I<Note:> the flattening behavior is different in Raku:
C<@b.unshift: @a> will unshift C<@a> into C<@b> as a single element. See also the
L<prepend method|/type/Array#method_prepend>.

Also note that C<unshift> in Raku returns the array to which was pushed,
contrary to Perl where it returns the new number of elements.

The Raku ecosystem has a module L<C<P5shift>|https://modules.raku.org/dist/P5shift>
which exports an C<unshift> function that mimics the original Perl behavior
as much as possible.

X<| untie - perlfunc>
=head2 untie

=item untie VARIABLE

Not supported in Raku, but see L<tie|/language/5to6-perlfunc#tie> for the
whole story.

The Raku ecosystem has a module L<C<P5tie>|https://modules.raku.org/dist/P5tie>
which exports an C<untie> function that mimics the original Perl behavior
as much as possible.

X<| use - perlfunc>
=head2 use

=item use Module VERSION LIST

=item use Module VERSION

=item use Module LIST

=item use Module

=item use VERSION

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

X<| utime - perlfunc>
=head2 utime

=item utime LIST

No equivalent.

X<| values - perlfunc>
=head2 values

=item values HASH

=item values ARRAY

=item values EXPR

Available in Raku. Can also be used as a method. C<values %hash> is
equivalent to C<%hash.values>.

X<| vec - perlfunc>
=head2 vec

=item vec EXPR, OFFSET, BITS

There is no support for vec() in Raku.

S29 says "Should replace C<vec> with declared buffer/array of C<bit>,
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.

X<| wait - perlfunc>
=head2 wait

=item wait

[NEEDS FURTHER RESEARCH] Unclear where this has gone. There's a C<wait>
method in C<Supply>, and an C<await> method in both C<Channel> and
C<Promise>. Which, if any or all, of these is a direct equivalent of
Perl's C<wait> is unclear.

X<| waitpid - perlfunc>
=head2 waitpid

=item waitpid PID, FLAGS

As with C<wait>, the disposition of this is unclear.

X<| wantarray - perlfunc>
=head2 wantarray

=item wantarray

There is no C<wantarray> in Raku; however, there are very easy ways to cover many of the use cases which wantarray filled.

First, since Raku does not need special reference syntax to contain
a C<List> or C<Array> in a C<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 C<.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 C<.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 Raku not to do so, even more so because I<void> context does not exist in Raku, with the closest equivalent being I<sink> context, since users can quite
easily turn any copy-producing method into a mutator using the C<.=>
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 C<.sink> method, which will be called when the result finds itself
in sink 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"

X<| warn - perlfunc>
=head2 warn

=item warn LIST

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

X<| write - perlfunc>
=head2 write

=item write FILEHANDLE

=item write EXPR

=item write

Formats are gone from Raku, so this no longer works.

X<| y/// - perlfunc>
=head2 y///

=item y///

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

=end pod

# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6
