Loading…

Online Perl Compiler and Playground

Browser-based compiler and playground for Perl, Progsity IDE.

About Perl

Perl was made for text: reading logs, pulling fields out of lines, and rewriting files in a few statements. Regular expressions are part of the syntax rather than a library, and hashes and lists are built in, which is why so many system scripts and bioinformatics pipelines are still written in it.

The playground runs Perl 5 with its core modules in a sandbox, so List::Util, POSIX, Data::Dumper and bigint are there to use. Start a script with use strict and use warnings: Perl forgives a great deal, and those two lines turn silent mistakes into messages.

The script is checked with perl -c before it runs, so a syntax error is reported once, with its line.

How to use

  1. Begin with use strict; and use warnings; then write the script at the top level.
  2. Read input from the stdin panel with <STDIN>, one line at a time, or all lines in a while loop.
  3. Press Run. Warnings go to the error panel with the line they came from.

FAQ

Which Perl runs here?›

Perl 5.36. It is Perl 5, not Raku (once called Perl 6), which is a different language.

Can I use CPAN modules?›

Only the modules that ship with Perl itself. The sandbox has no network, so nothing can be installed from CPAN.

How do I work with very large numbers?›

Add use bigint; and integers stop overflowing. Math::BigInt and Math::BigFloat are available for finer control.

Why does it print "syntax OK" in the compile output?›

That line is perl -c saying the check passed. Your program's own output is in the output panel.

Can I keep my scripts?›

Yes. Sign in and save a snippet; it gets a link you can open or share later.

Code examples

Tap “Try this” to load sample code into the editor above.

  • Count words with a hash

    use strict;
    use warnings;
    
    my %count;
    $count{$_}++ for split ' ', "to be or not to be";
    print "$_: $count{$_}\n" for sort keys %count;
  • Read two numbers

    use strict;
    use warnings;
    
    my ($x, $y) = split ' ', <STDIN>;
    print $x + $y, "\n";
  • Pull numbers out of text

    use strict;
    use warnings;
    
    my $text = "Order 66 shipped on day 12";
    my @numbers = $text =~ /(\d+)/g;
    print "@numbers\n";
  • Sort numbers

    use strict;
    use warnings;
    
    my @nums = (3, 1, 4, 1, 5, 9);
    print join(" ", sort { $a <=> $b } @nums), "\n";