Hello, I am trying to process a text file and print the output in a desired format. I am able to get a small piece of the code working, however i am finding it difficult to produce the results as expected, did some research and experimented with loading to hash etc. Didnt work as expected , any advice on how to proceed would really help. SCRIPT
#!/usr/bin/perl use strict; use warnings; my $data = 'input.txt'; my $placeholder = ''; unless(open(INPUT, $data)) { die "Can't open input file $data\n"; } # Print heading print "Product Release product Type color basic color all ov +erseas shipping\n"; while(my $line = <INPUT>) { if($line =~ m/Release Date(\d+)\/(\d+)\/(\d+)/) { print "$line"; } } close INPUT;
INPUT FILE (input.txt)
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
RESULTS
$ ./generate.pl Product Release product Type color basic color all overseas +shipping Release Date2/2/2019 Release Date2/2/2020 Release Date2/2/2021 Release Date2/2/2022 $
DESIRED RESULTS
Product Release product Type color basic color all + overseas shipping Release Date2/2/2019 analog white white,black,silve +r 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

In reply to process multiline text and print in desired format by ak_mmx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.