Thank you for reformatting; what you are requesting makes more sense now.

I have questions about the final sequence but I will let those go in favor of addressing the Perl elements first.

Something like this should help get you started, but it does not produce output in the same order you requested:

#!/usr/bin/perl -w use strict; # Loop through input filenames listed on command line foreach my $inpfnm (@ARGV) { # Try to open the file for read (input) if (!open INPFIL, "<$inpfnm") { print "ERROR: Cannot open input file '$inpfnm'\n"; } else { # Derive the output filename my $outfnm = $inpfnm . '-out.dat'; # Try to open the file for write (output) if (!open OUTFIL, ">$outfnm") { print "ERROR: Cannot open output file '$outfnm'\n"; } else { # Loop through lines from the input file while (my $inpbuf = <INPFIL>) { # Remove the newline at the end of the line chomp $inpbuf; # Split input by vertical bar (pipe) character my @inpelt = split /\|/, $inpbuf; # Go through each element from the split foreach my $inpelt (@inpelt) { if ($inpelt !~ /^\s*$/) { # Line is not blank. Proceed. # Prepare output buffer. my $outbuf = $inpelt; # Trim leading and trailing whitespace $outbuf =~ s/^\s+//; $outbuf =~ s/\s+$//; # Write output print OUTFIL "$outbuf\n"; } } } # Cleanup close OUTFIL; } # Cleanup close INPFIL; } } exit; __END__

It gets a little more complicated to process them in the order you requested, but not too much.

Let us know if you need the order you specified or if this sequence is sufficient to your needs.


In reply to Re: concatenating strings by marinersk
in thread concatenating strings by alferic

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.