Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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
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]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2015-11-25 23:38 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (693 votes), past polls