Search⌘ K
AI Features

Solution Review: Format Data

Explore how to use Perl regular expressions to match and format data properly. This lesson guides you through defining numeric and name patterns, combining them, and capturing variables to output formatted results.

We'll cover the following...

Solution

Let’s look at the solution before jumping into the explanation:

Perl
open(my $fh, $file);
my $number = qr/\d+/;
my $string = qr/[a-zA-Z]+/;
while(<$fh>) {
say "$1. Name: $3 $4. $2\t DOB: $7/$6/$5" if $_ =~ qr/\A($number),($string),($string),($string),($number)\-($number)\-($number)/;
}

Explanation

...