Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Re: push

by a (Friar)
on Feb 01, 2001 at 12:19 UTC ( #55668=note: print w/replies, xml ) Need Help??


in reply to Re: push
in thread push

Start w/: use strict, use perl -w. Trust us, it'll really help you here. But, enabler that I am: you're mixing up your arrays and hashes. You're also trying to read FILE twice:
my @coufields = split(/\t/, <FILE>);
should eat all of FILE, leaving nothing left for the while loop. Leave that line out and try:
my $debug = 5; print STDERR "Looking for id $courowid \n" if $debug > 8; while (<FILE>) { chomp; my ($id, $course) = split(/\t/); print STDERR "trying id $id, course $course\n" if $debug > 8; if ( $id == $courowid ) { print STDERR "found id $id, course $course\n" if $debug > 5; # if we match the ID, push the course name onto the # the array in the coudata hash, key $id push @{$coudata{$id}}, $course; } } print header; if ( %coudata ) { # found, display data by taking each course back outof # the array foreach my $id ( keys %coudata ) { print STDERR "show id $id\n" if $debug > 6; foreach my $course ( @{$coudata{$id}} ) { print STDERR "show id $id, course $course\n" if $debug > 8; print ul("$id: $course"); } # foreach my course } # foreach my id }else { # not found, show error print h1("Can't find row '$courowid'"); }
Its a big step in perl, but names are only half the battle: %coudata and $coudata{14146} are related but the first is the entire hash, the latter a single element found by key '14146'. @coudata is an entirely different kettle of data, its an array and the element $coudata[0] has no relation to the hash element $coudata{0}; just as @coudata doesn't have any relation to %coudata.
Plus, your variable names are troublesome: use english-ish things: course_list, course_id, search_id etc. You'll avoid typos (courdata coudata) and it'll make more sense. Just 'cause you can, doesn't mean its a good idea to to name an array and a hash the same thing. Its generally a bad idea, esp. early on. A few more keystrokes won't kill ya'

a

Replies are listed 'Best First'.
Re: Re: Re: push
by malaga (Pilgrim) on Feb 02, 2001 at 03:23 UTC
    thanks a, this was really helpful. - malaga

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://55668]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2022-01-27 06:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (70 votes). Check out past polls.

    Notices?