i am using the sub routine below when accessing 6 different text files that look something like this:

"ID" "Course" 9414 "Nutitional Epidemiology" 9414 "Nutritional assessment" 9414 "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"


Problem #1: in some cases it's ok to just list everything. but with one file i need to (i think) assign each item to a scalar so i can move it around in the order i want.

Problem #2: in either case i need to get rid of the ""'s, and the labels that are printing out, and also the ID number (the value we are searching on) Here's how it prints right now:

"ID": 9414 "Dept": "Division of Something" "Fax": "5551212" "MiddleName": "Title": "Professor of Something" "LastName": "Black" "Suffix": "PhD" "Address": "111 1st Street" "Email": "abc@acb.com" "FirstName": "Gladys" "Phone": "5551212" "Photo": "Black.jpg"


here's the code:

sub getrows { my $value = param('name'); my %data = (); my @fields = split(/\t/, <FILE>); chomp @fields; my @records; while(<FILE>) { chomp; my @row = split(/\t/); if ($row[0] eq $value) { my %data; @data{@fields} = @row; push @records, \%data; } } close (FILE); for my $ref (@records){ my %data = %$ref; print ul( map { li("$_: $data{$_}") } keys %data); } }#end getrows


i've been trying to do substiutions, or to extract only the part of the data i need, but i feel like i'm thrashing around and not making any headway. i was also trying to separate the printing into a different subroutine so that i can list the data in some cases but not others, but couldn't get the scoping right. can anyone tell me the best way to approach any of this? i would really appreciate it.

In reply to getting the right stuff by malaga

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.