Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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


In reply to Re: Re: push by a
in thread push by malaga

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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












    Results (74 votes). Check out past polls.

    Notices?