PetaPerl implements the Perl 5 built-in function library. This document lists all implemented functions, organized by category.
Legend:
- ✅ Fully implemented
- ⚠️ Partially implemented
- ❌ Not yet implemented
| Function | Status | Description |
print | ✅ | Print to filehandle or STDOUT |
say | ✅ | Print with newline |
printf | ✅ | Formatted print |
sprintf | ✅ | Formatted string |
print "Hello\n";
print $fh "data\n";
say "Hello"; # Adds newline
printf "%d items\n", $count;
my $str = sprintf "%05d", $num;
| Function | Status | Description |
open | ✅ | Open file or pipe |
close | ✅ | Close filehandle |
read | ✅ | Read fixed-length data |
sysread | ✅ | System-level read |
syswrite | ✅ | System-level write |
readline | ✅ | Read line(s) from filehandle |
getc | ✅ | Read single character |
eof | ✅ | Test for end-of-file |
seek | ✅ | Position filehandle |
tell | ✅ | Get filehandle position |
fileno | ✅ | Get file descriptor number |
binmode | ✅ | Set binary mode |
select | ✅ | Set default filehandle |
write | ✅ | Write formatted record |
open my $fh, '<', $filename or die $!;
my $data;
read $fh, $data, 1024; # Read 1024 bytes
my $line = readline($fh); # or <$fh>
my $char = getc($fh);
seek $fh, 0, 0; # Rewind to start
my $pos = tell $fh;
close $fh;
| Function | Status | Description |
opendir | ✅ | Open directory handle |
readdir | ✅ | Read directory entry |
closedir | ✅ | Close directory handle |
rewinddir | ✅ | Reset directory handle |
seekdir | ✅ | Position directory handle |
telldir | ✅ | Get directory position |
mkdir | ✅ | Create directory |
rmdir | ✅ | Remove directory |
chdir | ✅ | Change working directory |
opendir my $dh, $dir or die $!;
my @entries = readdir $dh;
closedir $dh;
mkdir "newdir", 0755 or die $!;
rmdir "olddir";
chdir "/tmp";
| Function | Status | Description |
unlink | ✅ | Delete files |
rename | ✅ | Rename file |
link | ✅ | Create hard link |
symlink | ✅ | Create symbolic link |
readlink | ✅ | Read symbolic link |
chmod | ✅ | Change file permissions |
chown | ✅ | Change file owner/group |
utime | ✅ | Change access/modification times |
truncate | ✅ | Truncate file to length |
stat | ✅ | Get file status |
lstat | ✅ | Get file status (no link follow) |
glob | ✅ | File name expansion |
unlink "file.txt" or die $!;
rename "old.txt", "new.txt";
link "source", "link";
symlink "target", "symlink";
my $target = readlink "symlink";
chmod 0644, @files;
chown $uid, $gid, @files;
utime $atime, $mtime, @files;
truncate $fh, $length;
my @info = stat $file;
my @info = lstat $symlink; # Doesn't follow symlink
my @files = glob "*.txt";
| Function | Status | Description |
length | ✅ | String/array length |
substr | ✅ | Extract/replace substring |
index | ✅ | Find substring position |
rindex | ✅ | Find substring (reverse) |
chr | ✅ | Number to character |
ord | ✅ | Character to number |
lc | ✅ | Lowercase string |
uc | ✅ | Uppercase string |
lcfirst | ✅ | Lowercase first char |
ucfirst | ✅ | Uppercase first char |
quotemeta | ✅ | Quote metacharacters |
chop | ✅ | Remove last character |
chomp | ✅ | Remove line ending |
hex | ✅ | Hex string to number |
oct | ✅ | Octal string to number |
pack | ✅ | Pack values into binary string |
unpack | ✅ | Unpack binary string |
vec | ✅ | Bit vector access |
my $len = length $str;
my $sub = substr $str, 0, 5; # First 5 chars
substr($str, 7, 5) = "replace"; # Lvalue substr
my $pos = index $str, "find";
my $rpos = rindex $str, "last";
my $char = chr(65); # "A"
my $code = ord("A"); # 65
my $lower = lc "HELLO"; # "hello"
my $upper = uc "hello"; # "HELLO"
my $cap = ucfirst "hello"; # "Hello"
chomp $line; # Remove \n if present
chop $str; # Remove last char
my $quoted = quotemeta '.*'; # '\\.\\\*'
my $num = hex "FF"; # 255
my $num = oct "377"; # 255
Lvalue substr: substr can be used as assignment target.
substr($str, 0, 3) = "New"; # Replace first 3 chars
| Function | Status | Description |
push | ✅ | Append to array |
pop | ✅ | Remove last element |
shift | ✅ | Remove first element |
unshift | ✅ | Prepend to array |
splice | ✅ | Remove/replace array elements |
join | ✅ | Join array with separator |
split | ✅ | Split string into array |
reverse | ✅ | Reverse list/string |
sort | ✅ | Sort list |
grep | ✅ | Filter list |
map | ✅ | Transform list |
push @arr, $val;
push @arr, @more;
my $last = pop @arr;
my $first = shift @arr;
unshift @arr, $val;
splice @arr, $offset, $length, @replacement;
my $str = join ",", @arr;
my @parts = split /,/, $str;
my @reversed = reverse @arr;
my @sorted = sort @arr;
my @sorted = sort { $a <=> $b } @numbers;
my @filtered = grep { $_ > 10 } @numbers;
my @doubled = map { $_ * 2 } @numbers;
Parallel execution: map, grep, and simple for loops may execute in parallel when safe.
| Function | Status | Description |
keys | ✅ | Get hash keys |
values | ✅ | Get hash values |
each | ✅ | Iterate key-value pairs |
exists | ✅ | Check if key exists |
delete | ✅ | Remove hash key |
my @keys = keys %hash;
my @vals = values %hash;
while (my ($k, $v) = each %hash) { ... }
if (exists $hash{key}) { ... }
my $removed = delete $hash{key};
Context sensitivity: keys and values return list in list context, count in scalar context.
my $count = keys %hash; # Number of keys
my @all_keys = keys %hash; # All keys
| Function | Status | Description |
abs | ✅ | Absolute value |
int | ✅ | Integer truncation |
sqrt | ✅ | Square root |
sin | ✅ | Sine |
cos | ✅ | Cosine |
exp | ✅ | e raised to power |
log | ✅ | Natural logarithm |
atan2 | ✅ | Arc tangent of y/x |
rand | ✅ | Random number |
srand | ✅ | Seed random number generator |
my $abs = abs -5; # 5
my $int = int 3.7; # 3
my $sqrt = sqrt 16; # 4
my $sin = sin $angle;
my $cos = cos $angle;
my $exp = exp 1; # e
my $log = log 10;
my $atan = atan2 $y, $x;
my $rand = rand 10; # 0 to <10
srand 42; # Seed with specific value
| Function | Status | Description |
ref | ✅ | Get reference type |
bless | ✅ | Bless reference into package |
defined | ✅ | Test if defined |
undef | ✅ | Undefine variable |
scalar | ✅ | Force scalar context |
my $type = ref $value; # 'ARRAY', 'HASH', 'CODE', etc.
my $obj = bless {}, 'MyClass';
my $obj = bless $ref, 'MyClass';
if (defined $var) { ... }
undef $var; # Set to undef
my $count = scalar @arr; # Force scalar context
| Function | Status | Description |
caller | ✅ | Get caller information |
wantarray | ✅ | Get calling context |
prototype | ✅ | Get subroutine prototype |
pos | ✅ | Get/set regex position |
study | ✅ | Optimize regex matching |
reset | ✅ | Reset variables |
my ($package, $file, $line) = caller;
my ($pkg, $file, $line, $sub) = caller(1);
if (wantarray) {
return @list;
} else {
return $scalar;
}
my $proto = prototype \&mysub;
my $pos = pos $str;
study $str; # Optimize for repeated regex
reset; # Reset ?? searches
| Function | Status | Description |
die | ✅ | Raise exception |
warn | ✅ | Print warning |
exit | ✅ | Exit program |
system | ✅ | Execute external command |
exec | ✅ | Execute and replace process |
fork | ✅ | Fork child process |
wait | ✅ | Wait for child |
waitpid | ✅ | Wait for specific child |
sleep | ✅ | Sleep for seconds |
time | ✅ | Get current Unix time |
times | ✅ | Get process times |
localtime | ✅ | Convert time to local |
gmtime | ✅ | Convert time to GMT |
getlogin | ✅ | Get login name |
die "Error: $!" if $error;
warn "Warning message";
exit 0;
my $status = system "ls", "-l";
exec "command", @args; # No return if success
my $pid = fork;
if ($pid == 0) {
# Child process
} else {
# Parent process
}
wait; # Wait for any child
waitpid $pid, 0; # Wait for specific child
sleep 5; # Sleep 5 seconds
my $now = time;
my @times = times; # (user, system, cuser, csystem)
my @lt = localtime time;
my @gmt = gmtime time;
my $user = getlogin;
All user/group database functions are implemented:
| Function | Status | Description |
getpwnam | ✅ | Get password entry by name |
getpwuid | ✅ | Get password entry by UID |
getpwent | ✅ | Get next password entry |
setpwent | ✅ | Reset password iteration |
endpwent | ✅ | End password iteration |
getgrnam | ✅ | Get group entry by name |
getgrgid | ✅ | Get group entry by GID |
getgrent | ✅ | Get next group entry |
setgrent | ✅ | Reset group iteration |
endgrent | ✅ | End group iteration |
my @pwinfo = getpwnam "username";
my @pwinfo = getpwuid $uid;
while (my @entry = getpwent) { ... }
endpwent;
my @grinfo = getgrnam "groupname";
my @grinfo = getgrgid $gid;
All network database functions are implemented:
| Function | Status | Description |
gethostbyname | ✅ | Get host by name |
gethostbyaddr | ✅ | Get host by address |
gethostent | ✅ | Get next host entry |
sethostent | ✅ | Reset host iteration |
endhostent | ✅ | End host iteration |
getnetbyname | ✅ | Get network by name |
getnetbyaddr | ✅ | Get network by address |
getnetent | ✅ | Get next network entry |
setnetent | ✅ | Reset network iteration |
endnetent | ✅ | End network iteration |
getprotobyname | ✅ | Get protocol by name |
getprotobynumber | ✅ | Get protocol by number |
getprotoent | ✅ | Get next protocol entry |
setprotoent | ✅ | Reset protocol iteration |
endprotoent | ✅ | End protocol iteration |
getservbyname | ✅ | Get service by name |
getservbyport | ✅ | Get service by port |
getservent | ✅ | Get next service entry |
setservent | ✅ | Reset service iteration |
endservent | ✅ | End service iteration |
my @host = gethostbyname "example.com";
my @net = getnetbyname "loopback";
my @proto = getprotobyname "tcp";
my @serv = getservbyname "http", "tcp";
| Function | Status | Description |
tie | ⚠️ | Bind variable to object (stub — returns undef) |
tied | ⚠️ | Get tied object (stub — returns undef) |
untie | ⚠️ | Unbind variable (stub — no-op) |
The functions are recognized and callable but do not dispatch to tie class methods. Modules depending on tie (e.g., Tie::File) will not function correctly.
| Function | Status | Description |
formline | ⚠️ | Format line (stub) |
write | ⚠️ | Write formatted output (stub) |
Perl formats are a legacy feature. The functions exist but the format output system is not implemented. Use printf/sprintf instead.
All socket operations are implemented:
| Function | Status | Description |
socket | ✅ | Create socket |
socketpair | ✅ | Create socket pair |
bind | ✅ | Bind socket to address |
listen | ✅ | Listen on socket |
accept | ✅ | Accept connection |
connect | ✅ | Connect to remote |
shutdown | ✅ | Shut down socket |
send | ✅ | Send data |
recv | ✅ | Receive data |
getsockopt | ✅ | Get socket option |
setsockopt | ✅ | Set socket option |
getsockname | ✅ | Get local address |
getpeername | ✅ | Get remote address |
| Function | Status | Description |
pipe | ✅ | Create pipe |
msgctl | ✅ | Message queue control |
msgget | ✅ | Get message queue |
msgsnd | ✅ | Send message |
msgrcv | ✅ | Receive message |
semctl | ✅ | Semaphore control |
semget | ✅ | Get semaphore set |
semop | ✅ | Semaphore operations |
shmctl | ✅ | Shared memory control |
shmget | ✅ | Get shared memory |
shmread | ✅ | Read shared memory |
shmwrite | ✅ | Write shared memory |
qr// is fully implemented including precompiled pattern reuse
(?{code}) embedded code execution is implemented
- Possessive quantifiers (
*+, ++, ?+) are implemented
- See Regular Expressions for remaining edge cases (self-referential captures, multi-char case folding)
use and require work for Pure Perl modules
- XS modules are not supported (native reimplementations provided for common ones)
- Some pragma effects may differ from perl5
- Most special variables are populated (
$^O, $^X, $], $^V, etc.)
Internals::SvREADONLY is not implemented
PetaPerl performs compile-time constant folding for:
length("hello") # Folded to 5 at compile time
substr("text", 0, 2) # Folded to "te"
These functions may execute in parallel when safe:
map - Parallel element transformation
grep - Parallel filtering
sort with pure comparison function
Parallelization requires:
- No side effects in the callback
- No shared mutable state
- Array size above parallelization threshold
- String functions use UTF-8 aware operations
- Array operations minimize copying
- Hash operations use optimized hash tables
- Math functions map to CPU instructions when possible