Perl has been around since 1987, and it earned its reputation on one thing: text. Log files, CSVs, config files, reports β Perl chews through text faster and with less code than almost anything else. Much of the early web ran on Perl, and it still runs a surprising amount of infrastructure, bioinformatics and system administration today.
Perl's superpower is regular expressions, built into the language rather than bolted on. Here is a one-liner that counts error lines in a log file:
# count lines containing "ERROR" in a log file my $count = 0 ; open my $fh , '<' , 'app.log' or die "Cannot open log: $!" ; while ( my $line = < $fh > ) { $count ++ if $line =~ / ERROR / ; } print "Errors: $count\n" ;
Enter fullscreen mode
Exit fullscreen mode
The =~ operator and the /pattern/ syntax are the heart of Perl. Once you learn a few regex basics, you can parse, filter and rewrite text in a handful of lines.β¦