Perl
1987fragletscriptingimperativefunctionalscripting.pl.pm
docker run --rm --platform="linux/amd64" 100hellos/perl:latest
MCP + fragletc
MCPstdinargs
This language supports code execution via MCP and the fragletc CLI. Stdin piping and argument passing are both supported.
Install fragletc →Perl is a scripting imperative and functional language first appearing in 1987.
Hello World
#!/usr/bin/env perl
# This is a slightly modified version of the script from:
# https://www.perlmonks.org/?node_id=329174
#
# You can do a simple "Hello World!" in Perl with:
# perl -e 'print "Hello World!\n"'
# BEGIN_FRAGLET
package Earth;sub Greet{
%_=('Y','~');$_='$;=!(Middle
Earth.age~~~<Eart~~~~~~~~~~~~~h
.age)?!(defined$ti~~~~~~~~~~~mez~~~On
e[2])?!(push@time~~~~~~~~~~~~~~~~Zone,loc
~altime())?rotation?~~~~~~~~~~~~~q~~?The Worl
~~d?:q:[\w]::q=[\~~~~~~~~~~~~~~~~~d~a-f]=:q?..~~
~~~?:q:.:;"42b3d3~~~~~~~~~~~~~~~~~~~~~728456c6c6f6
~~~~~0275f627c64672~~~~~~~~~~~~~~~~~~~~~b3072796e647
~~~~~~~42b3b3rg7d"=Ym~~~~~~~~~~~~~~~~~~~\$;~~*\;p~~~~u
~~~~~~~~~sh@_,$&;bless~~~~~~~~~~~~~~~~~~~~~~~~~$c~~~~~~~
~~~~~~~~~o~ntine~~~~~nt~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~s=\~~~~~~~$~~~~~~~~~~~~~~~~~~~~~~~pangaea~~~~
~~~~~~~~~~~~~~~;{l~~~~~~~~~~~~~~~~~~~~~~~~~~~~ocal@_;local$;
~~~~~~~~~~~~~~~~~="o~~~~~~~~~~~~~~~~~~~~~~~~~cean";$^A=(defi
~~~~~~~~~~~~~~~~~~~n~~~~~~~~~~~~~~~~~~~~~~~~~ed$continents)?
~~~~~~~~~~~~~~~~~~~(vec(~~~~~~~~~~~~~~~~~~~~~~$;, YYsplit(\'
~~~~~~~~~~~~~~~~~\',${\$;}~~~~~~~~~~~~~~~~~~~~~~)%3,YYsplit(
~~~~~~~~~~~~~~~~q??,$;)**2-~~~~~~~~~~~~~~~~~~~~~~(($;=Ytr/oa
~~~~~~~~~~~~~~~~eiu//)**2))=~~~~~~~~~~~~~~~~~~~~~~=28160)?q:
~~~~~~~~~~~~~~~~~.::q?!?:\'?~~~~~~~~~~~~~~~~~~~~~~\';}$^A=Ys
~~~~~~~~~~~~~~~~:\Q.\E:pack(~~~~~~~~~~~~~~~~~~~~~~\'h*\',j
~~~~~~~~~~~~~~~~~oin(q(),~~~~~~~~~~~~~~~~~~~~~~~grep{$_=
~~~~~~~~~~~~~~~~~~Ym,$,,}~~~~~~~~~~~~~~~~~~~~~~~split("
~~~~~~~~~~~~~~~~~",@_~~~~~~~~~~~~~~~~~~~~~~~~~~[0]))
~~~~~~~~~~~~~~~~):e~~~~~~~~~~~~~~~~~~~~~~~~~~~gexe
~~~~~~~~~~~~~~~;$d~~~~~~~~~~~~~~~~~~~~~~~~~~~="s
~~~~~~~~~~~~~~ort~~~~~~~~~~~~~~~~~~~~~~~~~~<=
~~~~~~~~~~~~>,~~~~~~~~~~~~~~~~~~~~~~~~~~YY
~~~~~~~~~~~@_~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~"~~~~~~~~~~~~~~~~~~~';;
s,(~|\r|\n|\s),,g;s.Y.\x7e.g;
eval};Greet;'the world';
# END_FRAGLETCoding Guide
Language Version
Perl 5.x
Execution Model
- Interpreted, runs directly from source
- Code executes at the top level
- Script runs once and exits
Key Characteristics
- Dynamic typing
- Case-sensitive
- Variables use sigils:
$(scalar),@(array),%(hash) - Context-sensitive (scalar vs list context)
- Automatic memory management
- Regular expressions are first-class
Fragment Authoring
Write valid Perl statements. Your fragment becomes the script body. Code runs at the top level of the script, so statements execute immediately. You can define subroutines, use variables, and call functions.
Available Packages
Standard Perl library is available. Core modules include:
strictandwarnings(recommended for production code)Data::Dumper- data structure debuggingFile::Find- file system traversalGetopt::Long- command-line option parsingJSON- JSON encoding/decoding (if installed)- Many more in the standard library
Common Patterns
- Print:
print "message\n"; - Variables:
my $name = "Alice"; - Arrays:
my @list = (1, 2, 3); - Hashes:
my %hash = (key => "value"); - Subroutines:
sub greet { my ($name) = @_; return "Hello, $name!"; } - Conditionals:
if ($condition) { ... } else { ... } - Loops:
for my $item (@list) { ... } - Regular expressions:
$str =~ s/pattern/replacement/;
Examples
# Simple output
print "Hello, World!\n";
# Variables and string interpolation
my $name = "Alice";
print "Hello, $name!\n";
# Arrays
my @numbers = (1, 2, 3, 4, 5);
my $sum = 0;
for my $num (@numbers) {
$sum += $num * $num;
}
print "Sum of squares: $sum\n";
# Functions
sub greet {
my ($name) = @_;
return "Hello, $name!";
}
print greet("World") . "\n";
# Hashes
my %colors = (
red => "#FF0000",
green => "#00FF00",
blue => "#0000FF"
);
print "Red: $colors{red}\n";
# Regular expressions
my $text = "Hello World";
$text =~ s/World/Perl/;
print "$text\n";
# List processing with map
my @squared = map { $_ * $_ } (1..5);
print "Squares: @squared\n";Caveats
- Always use
myto declare variables (avoids global scope pollution) - Remember to add newlines (
\n) to print statements for proper output - String interpolation only works in double quotes, not single quotes
- Array and hash access use different syntax:
$array[0]vs$hash{key} - Context matters:
@arrayin scalar context returns length, not the array itself
Fraglet Scripts
Echo Args
#!/usr/bin/env -S fragletc --vein=perl
print "Args: " . join(" ", @ARGV) . "\n";Perl Fortune
#!/usr/bin/env -S fragletc --vein=perl
# One from the vault: Perl fortunes
print "Perl: the only language that looks the same before and after RSA encryption.\n";Stdin Upper
#!/usr/bin/env -S fragletc --vein=perl
while (<STDIN>) { print uc($_); }Test
#!/usr/bin/env -S fragletc --vein=perl
package Earth;sub Greet{
%_=('Y','~');$_='$;=!(Middle
Earth.age~~~<Eart~~~~~~~~~~~~~h
.age)?!(defined$ti~~~~~~~~~~~mez~~~On
e[2])?!(push@time~~~~~~~~~~~~~~~~Zone,loc
~altime())?rotation?~~~~~~~~~~~~~q~~?The Worl
~~d?:q:[\w]::q=[\~~~~~~~~~~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