in reply to hash/array

malaga: may I ask what you plan to use this for? In reading through your posts, they seem so painfully vague that I can't help but suspect that you are asking us for help with homework. That's a bit of a touchy point here.

From your past code, you appear to know how to open files. What you seem to be missing is that you should probably use split to get the data you want and then test the first element of the array that's created. I started writing a skeleton of the program, only to realize that I'm not sure that this is appropriate. If you do need assistance with homework, that's fine. Just let us know so that we can offer advice, rather than answers. Otherwise, you're cheating yourself in addition to your professor.

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Replies are listed 'Best First'.
Re: (Ovid - homework?) Re: hash/array
by malaga (Pilgrim) on Jan 26, 2001 at 00:21 UTC
    no, not homework. work work. i would post the code i have, but i've changed it so many times i don't know where i'm at. i just need to get that one row from the text file, then turn it into html.
      malaga wrote:
      ...but i've changed it so many times...
      With all due respect, this implies that you probably started coding your program without designing it first. Let's try a bit of pseudo-code mixed with step-wise refinement. Here's what you said you needed:
      open a text file that has rows and colums (tab delimited), look for a name (in the first column), get the row that has the name so i can do stuff to it.
      Break that into separate lines and you have pseudo-code!
      open a text file (tab delimited) look for a name in the first column get the row that has the name so i can do stuff to it.
      That pretty much covers the task. Further refinement gets this:
      open a text file while I read a line from the file look for a name in the first column if the name is what I want, do stuff to the row end while
      Even more refinement:
      # still pseudo-code here open inputFile or die while ( read line from inputFile ) { get first item from tab-delimited line if ( first item equals "something I need" ) { do something important } } close file
      That's a pretty simple example. However, larger programs can be tackled in a similar fashion (though I use Warnier-Orr). There's probably nothing in the above pseudo-code that you can't figure out. By breaking it down that way, it's much easier to conceptualize and follow the logic.

      In fact, if you do have a problem with the above pseudo-code, I suspect that it's in the following line: "get first item from tab-delimited line". Now, rather than having a vague problem that you don't know how to approach (second quote above), you have a very specific task that is much easier to deal with.

      Cheers,
      Ovid

      Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

        That is a very cool way to do it.
        But further: after your pseudocode is nearly done,
        =head1 PSEUDOCODE
        =cut
        around it. its too valuable to lose. By all means leave the comments in the code, but keep it all together as well. Sure it adds a couple lines, but will appreciate it big time, come maintenance day.
        --
        Jay "Yohimbe" Thorne, alpha geek for UserFriendly
        thanks ovid. i actually did think about, and design my problem, but there is something about arrays that hasn't sunk in yet, so i get confused and trash it. thanks for the help.
        i'm restating my problem, because i tried out each of the suggestions, and i couldn't get where i need to go with any of them. i am very much a beginner and am working hard on this, but spinning my wheels - i appreciate the help.

        i have a table like this: rowid course1 course2 course3 course4 marge psychology math engineering pe roy math reading art cooking etc. one of these fields will have lots of text with line breaks. i have a form. the form will send a request to a cgi, passing a value + which matches a value in "rowid" from the table. i need to open the file that contains the table, find the row that mat +ches the value passed by the form, read that row into an array (or ha +sh?) and print it out in html. i'm able to open the file and put it into an array and print it, but i + don't know enough perl yet to take just the row i want and assign la +bels to each value.