# File handling

**URL:** <https://www.ruby-forum.com/t/file-handling/124092>\
**Category:** Ruby\
**Created:** [December 24, 2007, 4:59pm UTC](https://www.ruby-forum.com/t/file-handling/124092 "2007-12-24T16:59:50Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![advait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e19adc/32.png) [@advait](https://www.ruby-forum.com/u/advait)\
**Post date:** [December 24, 2007, 4:59pm UTC](https://www.ruby-forum.com/t/file-handling/124092/1 "2007-12-24T16:59:50Z")

</div>

Hi,

I have to make use of a single associative array to hold two files and I  
should be able to access them in the following manner

1. [’’] to have info related to group  
2 [’’][’’]  
3 [’’,’’,’’]

The file, along with the two group are

abc.qq

Names sub1 sub2 sub3 sub4

zzz 22 32 40 10  
. . . . .  
. . . . .  
.  
.

def.qq

Names sub1 sub2 sub3 sub4

How do I do this task…

Thank You

ARB

zzz 22 32 40 10  
. . . . .  
. . . . .  
.

How do I achieve this

---

<div class="post-metadata">

**Author:** ![advait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e19adc/32.png) [@advait](https://www.ruby-forum.com/u/advait)\
**Post date:** [December 24, 2007, 10:01pm UTC](https://www.ruby-forum.com/t/file-handling/124092/2 "2007-12-24T22:01:39Z")

</div>

On 24.12.2007 16:59, Advait B. wrote:

> abc.qq
> 
> Names sub1 sub2 sub3 sub4
> 
> zzz 22 32 40 10  
> . . . .  
> . . . .

From what you’ve written it’s unclear to me

- whether you want an in memory structure or persistent data,

- what you have implemented so far,

- what it is that you are asking.

I’d say there is some room for improvement of your original posting. 🙂

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![advait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e19adc/32.png) [@advait](https://www.ruby-forum.com/u/advait)\
**Post date:** [December 25, 2007, 4:57am UTC](https://www.ruby-forum.com/t/file-handling/124092/3 "2007-12-25T04:57:54Z")

</div>

On Dec 24, 2007 3:00 PM, Robert K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > The file, along with the two group are
> 
> - whether you want an in memory structure or persistent data,
> 
> - what you have implemented so far,
> 
> - what it is that you are asking.
> 
> I’d say there is some room for improvement of your original posting. 🙂

I agree with robert. I think I know what you want to do, but just am  
not sure.

Todd

---

<div class="post-metadata">

**Author:** ![advait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e19adc/32.png) [@advait](https://www.ruby-forum.com/u/advait)\
**Post date:** [December 26, 2007, 11:45am UTC](https://www.ruby-forum.com/t/file-handling/124092/4 "2007-12-26T11:45:28Z")

</div>

On 26.12.2007 09:17, Advait B. wrote:

> > > I’d say there is some room for improvement of your original posting. 🙂  
> > > I am really sorry for not describing by dought properly.  
> > > student3 85 84 89  
> > > 88 91 75 student14 95
> 
> Now I need to put both these file into and array (single associative  
> array) and read them  
> simeltaneously meaning when I execute this program typing the  
> "group\_name " followed by “student\_name” I should get the result

What is a “group name”? I can guess on the student name but am at a  
loss with regard to this “group name”.

> ex  
> ABC student3  
> o/p =\> student3 85 84 89
> 
> similarly  
> DEF student12
> 
> o/p =\> 77 84 96 student12 84
> 
> How could I achieve this

Frankly, this looks like a homework assignment and I am reluctant to  
implement this for you. Also it seems, the spec is not yet fully clear  
(to you). So while we have a pretty good specification (or rather  
example) of the input data, it is still not clear to me what output you  
expect. You talk about putting your input data into a single  
associative array which is implementation terminology. But the  
important bit is to get the _requirements_ straight _first_.

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![advait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e19adc/32.png) [@advait](https://www.ruby-forum.com/u/advait)\
**Post date:** [December 27, 2007, 2:15am UTC](https://www.ruby-forum.com/t/file-handling/124092/5 "2007-12-27T02:15:49Z")

</div>

On Dec 26, 2007 4:44 AM, Robert K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > 
> 
> Kind regards
> 
> ```
> robert
> 
> ```

I’m still not sure, but I think Advait wants to search for a line in a  
file. Is that true, Advait?

Todd

---

<div class="post-metadata">

**Author:** ![advait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e19adc/32.png) [@advait](https://www.ruby-forum.com/u/advait)\
**Post date:** [December 26, 2007, 12:20pm UTC](https://www.ruby-forum.com/t/file-handling/124092/6 "2007-12-26T12:20:41Z")

</div>

On Dec 26, 4:43 am, Robert K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Also it seems, the spec is not yet fully clear  
> (to you).

That was my thought. It seems the OP wants treat two different streams  
as the same kind of data (but keyed on different values). I can think  
of a way to abstract this, but it just “feels” wrong. Seems like this  
kind of thing is best suited to a DB/ORM mapping rather than trying to  
do it by hand.

Regards,  
Joordan

---

<div class="post-metadata">

**Author:** ![advait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e19adc/32.png) [@advait](https://www.ruby-forum.com/u/advait)\
**Post date:** [December 27, 2007, 4:24pm UTC](https://www.ruby-forum.com/t/file-handling/124092/7 "2007-12-27T16:24:47Z")

</div>

Todd B. wrote:

> On Dec 26, 2007 4:44 AM, Robert K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > > 
> > 
> > Kind regards
> > 
> > ```
> > robert
> > 
> > ```
> 
> I’m still not sure, but I think Advait wants to search for a line in a  
> file. Is that true, Advait?
> 
> Todd

Hi,

Ya thats right I want to search a line in the file

---

<div class="post-metadata">

**Author:** ![advait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e19adc/32.png) [@advait](https://www.ruby-forum.com/u/advait)\
**Post date:** [December 26, 2007, 9:17am UTC](https://www.ruby-forum.com/t/file-handling/124092/8 "2007-12-26T09:17:12Z")

</div>

Todd B. wrote:

> On Dec 24, 2007 3:00 PM, Robert K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > > The file, along with the two group are
> > 
> > - whether you want an in memory structure or persistent data,
> > 
> > - what you have implemented so far,
> > 
> > - what it is that you are asking.
> > 
> > I’d say there is some room for improvement of your original posting. 🙂
> 
> I agree with robert. I think I know what you want to do, but just am  
> not sure.
> 
> Todd

Hi,

I am really sorry for not describing by dought properly.

I have two files ABC.tvs and DEF.tvs, both these files house  
student data as shown below

ABC.tvs  
…

Names Hindi English Mathematics  
student1 90 75 80  
student2 77 84 96  
student3 85 84 89  
student4 88 91 75

and the other file

DEF.tvs  
…  
Hindi English Sanskrit Names Biology  
90 75 80 student11 88  
77 84 96 student12 84  
85 84 89 student13 99  
88 91 75 student14 95

Now I need to put both these file into and array (single associative  
array) and read them  
simeltaneously meaning when I execute this program typing the  
"group\_name " followed by “student\_name” I should get the result

ex  
ABC student3  
o/p =\> student3 85 84 89

similarly  
DEF student12

o/p =\> 77 84 96 student12 84

How could I achieve this

Thanking you

ARB
