in reply to process multiline text and print in desired format

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11129830 use warnings; my $format = "%-25s%-15s%-14s%-24s%s\n"; printf $format, split / +/, 'Product Release product Type c +olor basic color all overseas shipping'; local ($/, @ARGV) = ('', 'input.txt'); while( <> ) { printf $format, /(Release Date\S+)/ ? "$1" : 'N/A', /(?|product clock\d\((\w+)\)|product (\w+))/ ? "$1" : 'N/A', /color basic (\S+)/ ? "$1" : 'N/A', /color all (\S+)/ ? "$1" : 'N/A', /overseas shipping (\w+)/ ? "$1" : 'N/A'; }

Outputs:

Product Release product Type color basic color all + overseas shipping Release Date2/2/2019 analog white white,black,silv +er N/A Release Date2/2/2020 none N/A N/A + N/A Release Date2/2/2021 digital black black,silver + N/A Release Date2/2/2022 digital white white + yes

Replies are listed 'Best First'.
Re^2: process multiline text and print in desired format
by ak_mmx (Novice) on Mar 18, 2021 at 02:05 UTC
    Thanks for putting time to write the code. would you please advise on the pattern match ? input file has leading spaces for all lines except "Release Date.xxxxx" your suggestion seems to match without the regex for whitespaces. /color basic /color all /overseas shipping

      There is no need to match the whitespace at the beginning of lines. A match can start anywhere.