Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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


Comment on Re: concatenating text files before reading
Select or Download Code
Re^2: concatenating text files before reading
by Hossein (Acolyte) on Sep 05, 2013 at 09:17 UTC
    Thank you :) Sorting is not needed:)

    Regards

    Hossein

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2014-09-22 19:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (198 votes), past polls