i posted this question for tilly but i should have posted it here so everyone can see it. please excuse the duplication
i have been trying to tweak this script to cover one more aspect of what i am doing - i need to search for all rows that have a particular id, not just the first one. here's where the script is:
open FILE , "/courses.txt" or die "Cannot open: $!";
my $couvalue = param('name');
my $courowid = $ARGV[0] || $couvalue;
my %coudata = ();
my @coufields = split(/\t/, <FILE>);
chomp @coufields;
while(<FILE>) {
chomp;
my @courow = split(/\t/);
if ($courow[0] eq $courowid) {
@coudata{@coufields} = @courow;
last;
}
}
close (FILE);
print header;
if ( keys %coudata ) {
# found, display data
print ul( map { li("$_: $coudata{$_}") } keys %coudata);
}
else {
# not found, show error
print h1("Can't find row '$courowid'");
}
#######this is what the table looks like:
1414 "Nutitional Epidemiology"
1414 "Nutritional assessment"
1414 "Undernutrition in the United States"
1371 "Health Politics and Policy"
1371 "Advanced Health Politics?"
1371 "Introduction to Health Policy & Management"
1371 "Health and Public Policy Seminar"
i only get one row back.
i've tried taking out "last;"
i've tried to do a foreach instead of an if, but i can't get it to work. i've even posted another sopw, in trying to use "push" to get all the lines that match into one array.
can this script work for this problem, and if so, where should changes be made?
thank you for your help.
malaga
In reply to Re: push
by malaga
in thread push
by malaga
-
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 How to display code and escape characters
are good places to start.
|