473,397 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Reading files into memory

Hi
I want to be able to load files into memory and then carry out my computation. Here is the thing, I have over 10000 files with average 50KB data. I need to store all of them in my RAM. Assuming I have the necessary RAM, how do i do this. I need to be able to go to each line of each file later on, which is to say I need easy access to data inside these files. I wrote this but this does not work:

my %table1=();
for($var=1;$var<2; $var++)
{
....
.......
.........
open A, $mov_i || die "Shit there is some prob here $!";
$table1{$var} = <A>;
close A;
}

foreach $row ($table1{1})
{
print "$row\n";
}

This just prints the first row of the file. But if i replce $table1{$var} with @table1 then I can get the contents of that file, but the problem is that I need to store all the files in a table for easy access to their data.

Rahul
Nov 3 '06 #1
1 2911
miller
1,089 Expert 1GB
open A, $mov_i || die "Shit there is some prob here $!";
$table1{$var} = <A>;
close A;

The above code will not work as you expect. I think you need to read up more on file operations in perl. As a quick fix though, you can add the following line to your code.

Expand|Select|Wrap|Line Numbers
  1. {
  2.     local $/;
  3.     $table1{$var} = <A>;
  4. }
  5.  
This will cause the entire file to be slurped into your data structure as wanted. If you're plannong on doing operatiosn on the individual lines of your file though, it would make more sense to save the file in an array data structure. Nevertheless, the above code will solve your initial problem. You can hopefully take it from here.
Nov 3 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: christos panagiotou | last post by:
hi all I am trying to open some .raw files that represent images (256x256, 8 bit per pixel, no header) in a c++ program I cannot copy paste the module here as it uses a method from the VTK...
4
by: Sebastian Becker | last post by:
Hello NG, is fscanf capable of reading a memory adress from a file? I tried to find the right format-parameter, but my code doesn't seem to work... Regards, Sebastian
8
by: Darsant | last post by:
I'm currently reading 1-n number of binary files, each with 3 different arrays of floats containing about 10,000 values a piece for a total of about 30,000 values per file. I'm looking for a way...
20
by: sahukar praveen | last post by:
Hello, I have a question. I try to print a ascii file in reverse order( bottom-top). Here is the logic. 1. Go to the botton of the file fseek(). move one character back to avoid the EOF. 2....
40
by: googler | last post by:
I'm trying to read from an input text file and print it out. I can do this by reading each character, but I want to implement it in a more efficient way. So I thought my program should read one...
3
by: Brad | last post by:
I'm working on a web app which will display LARGE tiff image files (e.g files 10-20+ mb). Files are hidden from users direct access. For other, smaller image files I have used FileStream to read...
7
by: jccorreu | last post by:
I've got to read info from multiple files that will be given to me. I know the format and what the data is. The thing is each time we run the program we may be using a differnt number of files,...
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
5
blazedaces
by: blazedaces | last post by:
Ok, so you know my problem, java is running out of memory reading with SAX, the event-based xml parser intended more-so than DOM for extremely large files. I'll try to explain what I've been doing...
17
by: byte8bits | last post by:
How does C++ safely open and read very large files? For example, say I have 1GB of physical memory and I open a 4GB file and attempt to read it like so: #include <iostream> #include <fstream>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.