Okay, use <> (see "I/O Operators" in the perlop manpage) to read successive lines of your table. For each line you read, use split (perlfunc)to split up the line into an array (perldata) and if (perlsyn) to check if it's the right one. If it is, you can use a hash slice (perldata again) to easily assign the row's values to a hash to be used.

use strict; use Data::Dumper; my $rowid = $ARGV[0] || 'roy'; my %data = (); my @fields = split(/\t/, <DATA>); chomp @fields; while(<DATA>) { chomp; my @row = split(/\t/); if ($row[0] eq $rowid) { @data{@fields} = @row; last; } } if ( keys %data ) { # found, display data print Dumper \%data; } else { # not found, show error print STDERR "Can't find row '$rowid'\n"; } __DATA__ rowid course1 course2 course3 course4 marge psychology math engineering pe roy math reading art cooking

So now you'll need to replace reading from DATA with reading from an open filehandle, use CGI to get the $rowid passed from the form and put whatever HTML you want in the found/not found sections.

Good luck.


In reply to Re: Re: Re (tilly) 3: hash/array by eg
in thread hash/array by malaga

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.