Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: process multiline text and print in desired format

by tybalt89 (Monsignor)
on Mar 17, 2021 at 17:25 UTC ( [id://11129835]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11129835]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-20 02:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found