Hi thanos1983
I think basically, what you are trying to do is to concatenate several files, with little manipulations here and there, going by the sample of files as input and output at the end of your post. If that is right, then what I will advice is put the for loop to loop over the files outside the subroutine to read the files. By that you can get the names of the files to read from one after another and use your subroutine to read and write.
Something to give a head up:
use warnings; use strict; reader($_) for (@ARGV); sub reader { my ($filename) = @_; open my $fout, '>>', 'output_file.txt' or die "can't open file: $! +"; open my $fh, '<', $filename or die "can't open file: $! +"; while (<$fh>) { print $fout $_; } print $/; }
Of course, you have to pass all the files to read from, from the CLI.
Like: $ perl read_n_write.pl file1.txt file2.txt file3.txt ...
If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me

In reply to Re: Concatenating arrays fetched from different text files by 2teez
in thread Concatenating arrays fetched from different text files by thanos1983

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.