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
#!/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
Download from the command line
curl -L -o sample.pl https://files.samplefiles.com/code/pl/sample.plwget https://files.samplefiles.com/code/pl/sample.plhttps://files.samplefiles.com/code/pl/sample.plprintf '%s %s\n' 0aaf3d0b528f3c0a5ba3620650a0b801cb8cd69a993b532fef4af03049d1266b sample.pl | shasum -a 256 -cOr check the download in your browser with the checksum calculator.