Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: concatenating text files before reading

by 2teez (Vicar)
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]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (1)
As of 2018-05-26 03:29 GMT
Find Nodes?
    Voting Booth?