Please help me out if you can... I currently want to read in the following data file.
"PER" "A1" "Denise Johnson" "red,orange,yellow" 09/25/2001 "PER" "A2" "Desiree Smith" "yellow,blue-green" 03/06/1970 "EMP" "A1" "X & Y Bank" "Teller" 05/17/1994 "Brian's Point" "WI" 54997 24000 +.00 "EMP" "A2" "Acme Corp" "Computer Programmer" 07/24/1997 "Maxwell" "WI" 53224 + 45000.00 "EOS"
What I would like to be able to do is read in all of the PER info and EMP info where the first field (A1 or A2) are matching and then put them into a similar hash and thus come through with the following output.
--------------------- Entity = A1 Name = Denise Johnson Color = red Color = orange Color = yellow Date = 09/25/2001 ---------------------- Entity = A2 Name = Desiree Smith Color = yellow Color = blue-green Date = 03/06/1970 ------------------------ Entity = A1 Employment = X & Y Bank Job Title = Teller Date of Hire = 05/17/1994 Location = Brian's Point, WI 54997 Salary = 24000.00 ------------------------ Entity = A2 Employment = Acme Corp Job Title = Computer Programmer Date of Hire = 07/24/1997 Location = Maxwell, WI 53224 Salary = 45000.00
Here is my code so far, but it is not giving me the correct result (actually it is giving me NO RESULT). Please help me if you can, but do not laugh to hard at me, please....
#!/usr/bin/perl-Tw use strict; use Text::ParseWords; open(DATA,"basicdez.dat") || die "Cannot open datfile: $!\n"; my @data; my $i = 0; my $new_record = 0; while (<DATA>) { chomp; last if /^"EOS"$/; { @data = &quotewords('\s+', 0, $_); } if ((/^PER\s*$/) && ($data[0]) && ($data[1]) && ($data[2]) && ($data +[3])) { my @colors=split(/,/, $data[2]); print "---------------------\n"; print "Entity = $data[0]\n"; print "Name = $data[1]\n"; for (@colors){ # print each color print "Color = $_\n"; print "Date = $data[3]\n"; } if ((/^EMP\s*$/) && ($data[0]) && ($data[1]) && ($data[2]) && ($data +[3]) && ($data[4]) && ($data[5]) && ($data[6]) && ($data[7])) { print "------------------------\n"; print "Entity = $data[0]\n"; print "Employment = $data[1]\n"; print "Job Title = $data[2]\n"; print "Hire Date = $data[3]\n"; print "Location = $data[4], $data[5] $data[6]\n"; print "Salary = $data[7]\n"; } } }
I do need to use the PER and EMP as seperators to sort out the data, so if you could tell me a way to put this information together without to much stress that would be great. Anything you could do to help out would be awesome at this point. peace, LOVE and ((hugs)) as always dez L

In reply to Help with creating output to screen... by basicdez

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.