Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Concatenating arrays fetched from different text files

by 2teez (Vicar)
on May 29, 2014 at 00:20 UTC ( [id://1087743]=note: print w/replies, xml ) Need Help??


in reply to Concatenating arrays fetched from different text files

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

Replies are listed 'Best First'.
Re^2: Concatenating arrays fetched from different text files
by thanos1983 (Parson) on May 29, 2014 at 09:21 UTC

    To: 2teez,

    This is what I was thinking of doing too. I will have a go and see what happens. Thank you for your time and effort replying to my question.

    Seeking for Perl wisdom...on the process...not there...yet!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (7)
As of 2024-03-28 22:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found