in reply to Re: Re (tilly) 3: hash/array
in thread hash/array
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re (tilly) 3: hash/array
by Anonymous Monk on Jan 26, 2001 at 23:17 UTC | |
by tilly (Archbishop) on Feb 02, 2001 at 10:36 UTC | |
by malaga (Pilgrim) on Feb 02, 2001 at 23:25 UTC | |
by malaga (Pilgrim) on Feb 01, 2001 at 02:29 UTC | |
by repson (Chaplain) on Feb 01, 2001 at 17:29 UTC | |
by malaga (Pilgrim) on Feb 02, 2001 at 03:31 UTC | |
|
Re: Re: Re: Re (tilly) 3: hash/array
by malaga (Pilgrim) on Feb 02, 2001 at 23:23 UTC |