Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: concatenating text files before reading

by 2teez (Priest)
on Sep 05, 2013 at 09:05 UTC ( #1052519=note: print w/replies, xml ) Need Help??

in reply to concatenating text files before reading

Hi Hossein,
I need to read several (small) text files (all files in same dir)
look into using opendir to open your directory, then you can use readdir to get your files to read, using open.
However, one need ask; Is the ORDERing of your files contained in your directory important? If so, you might have to sort your file in a way to get the final content in the a correct order.
* The content of all files are supose to go into one scalar $content
You can initialize a string say my $content = ""; then when you open and read through each of the files, chomping the newlines from each lines you can concatenate like so

... while(my $line = <$fh>){ chomp $line; $content .= $line; }
* Update.

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 text files before reading
by Hossein (Acolyte) on Sep 05, 2013 at 09:17 UTC
    Thank you :) Sorting is not needed:)



Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1052519]
[stevieb]: for the first time ever, I will have 100% of the documentation and unit tests written for a new distribution before writing even a single character of the C or Perl code required :)

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (17)
As of 2017-01-20 16:42 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (176 votes). Check out past polls.