in reply to getting the right stuff

ok, i'm getting soooo close (maybe). i now have just the course printing, but it's printing the same course for each key. what am i doing wrong?
my $value = param('name');#the value passed from the webpage my %data = (); my @fields = split(/\t/, <FILE>); my $row; my $id; my $course; chomp @fields; my @records; my @course; while(<FILE>) { chomp; my @row = split(/\t/); if ($row[0] eq $value) { ($id, $course) = split (/\t/); my %data; #then put the row into a hash. @data{@fields} = @row; push @records, \%data; } } close (FILE); for my $ref (@records){ my %data = %$ref; print ul( map { ul("$course") } keys %data);

Replies are listed 'Best First'.
Re: Re: getting the right stuff
by eg (Friar) on Feb 07, 2001 at 05:14 UTC
    print ul( map { ul("$course") } keys %data);

    looks wrong. What you're doing here is printing the same $course (which contains the last course read) for every record. Also you're going to get Extremely Funky HTML (lists inside lists, without any items?) What you want is probably something like:

    print "<ul>"; foreach my $ref ( @records ) { print "<li>", $ref->{Course}, "</li>"; } print "</ul>";

    Do you see the difference? While $course refers to the variable that never changes in your final loop, whereas $ref->{course} refers to the data in the hash reference whose key is the string "course". This does change because $ref changes for every iteration.

    Update: changes "course" to "Course" in key.

      that's giving me an empty bulleted list. i'm still playing around with it, but i'm not getting anything yet.