Code · 1 file

Sample Perl File

Perl is a text-processing and scripting language still used in sysadmin tooling. The Perl sample is a small program — a customer record, a VIP check and a formatted total — that is the same in every language we offer, so you can compare them side by side.

Perl · 524 B

Sample Perl file

An idiomatic Perl example: a customer record type, a VIP check, a total and a formatted loop — the same program in every language we offer.

CC0 · free for any use · Verified by an independent tool · Report a problem

sample.pl — first linesPerl
#!/usr/bin/env perl
# Sample Perl script — samplefiles.com
use strict;
use warnings;
use List::Util qw(sum);

my @customers = (
    { id => 1, name => 'Ada',   balance => 12500 },
    { id => 2, name => 'Grace', balance => 830.5 },
    { id => 3, name => 'Linus', balance => 10000 },
);

sub is_vip { my ($c) = @_; return $c->{balance} >= 10_000 }

for my $c (@customers) {
    printf "%-6s %10.2f %s\n", $c->{name}, $c->{balance}, is_vip($c) ? 'VIP' : '';
}
printf "Total: %.2f\n", sum(map { $_->{balance} } @customers);

File details

Size
524 B (524 bytes)
MIME type
text/x-perl
SHA-256
0aaf3d0b528f3c0a5ba3620650a0b801cb8cd69a993b532fef4af03049d1266b
MD5
bcba7e948602969a8c2f0dc558848bcc

Download from the command line

curl -L -o sample.pl https://files.samplefiles.com/code/pl/sample.pl

Or check the download in your browser with the checksum calculator.