in reply to (Ovid - design your programs) Re(3): hash/array
in thread hash/array

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.

Replies are listed 'Best First'.
Re: Re: (Ovid - design your programs) Re(3): hash/array
by repson (Chaplain) on Jan 26, 2001 at 14:28 UTC
    Okay, lets say your array is like this (Supersplit is the simplest way to create it)
    $ary[0][0]='marge'; $ary[0][1]='phychology'; $ary[0][2]='math'; $ary[1][0]='roy'; # etc...
    Then you want to search the first column of that array for the desired rowid, and print it out in an html table.
    my $rowid = $q->param('rowid'); # get the value from our CGI.pm objec +t # search the first column for the rowid, and store the first match in +$row_ref my ($row_ref) = grep { $_->[0] eq $rowid } @ary; # output an html table containing column head labels and a row of data print '<table>', '<tr><td>rowid</td><td>course1</td><td>course2</td></tr>', '<tr>', (map {"<td>$_</td>"} @$row_ref), '</tr>', '</table>';
    Hope that helps in some kind of way, I'm not sure what else you want.