#!/usr/bin/env perl use strict; use warnings; local $/ = "\n\n"; # Set the input record separator to double-newline so that each # grouping can be treated as a single record. output('Product Release', 'product Type', 'color basic', 'color all', 'overseas shipping'); while (my $record = ) { my ($date, $product, $color_basic, $color_all, $overseas, $shipping_charges, $warranty, $status); if ($record =~ m{^Release\s+Date(\d+/\d+/\d+)\n\s*product\s+(.+)$}m) { ($date, $product) = ($1, $2); $color_basic = $record =~ m/^\s*color\s+basic\s+(.+)$/m ? $1 : 'N/A'; $color_all = $record =~ m/^\s*color\s+all\s+(.+)$/m ? $1 : 'N/A'; $overseas = $record =~ m/^\s*overseas\s+shipping\s+(.+)$/m ? $1 : 'N/A'; $shipping_charges = $record =~ m/^\s*shipping\s+charges\s+(.+)$/m ? $1 : 'N/A'; $warranty = $record =~ m/^\s*warranty\s+(.+)$/m ? $1 : 'N/A'; $status = $record =~ m/^\s*(.+)\Z(?!.)/m ? $1 : 'No status'; output("Release Date$date", $product, $color_basic, $color_all, $overseas); } else { warn "Bad record: $record\n"; } } sub output { my @fields = @_; printf "%-24s%-32s%-24s%-24s%-24s\n", @fields; } __DATA__ Release Date2/2/2019 product clock1(analog) color basic white color all white,black,silver warranty 1 year not sold yet Release Date2/2/2020 product none Release Date2/2/2021 product clock1(digital) color basic black color all black,silver warranty 1 year not sold yet Release Date2/2/2022 product clock2(digital) color basic white color all white overseas shipping yes shipping charges yes warranty 1 year not sold yet #### Product Release product Type color basic color all overseas shipping Release Date2/2/2019 clock1(analog) white white,black,silver N/A Release Date2/2/2020 none N/A N/A N/A Release Date2/2/2021 clock1(digital) black black,silver N/A Release Date2/2/2022 clock2(digital) white white yes