jrsimmon, thank you for the response.
I would get the data i expected and then in between I would get a "Use of uninitialized value $key in print at multiline.pl line 22, <PF> line 1." and then it would continue and spit out some more data, and then the error inbetween.
I am not sure what causes the error message. But now I simply do a check if my variable eq "" and if so skip to the next, and then I get rid of the error.
I wanted to put pairs of into into a hash, but when I tried doing that I would get the Odd number of elements error .. But now I could finally succesfully make the hash.
I did not have any blank lines in the data file, so what caused the uninitialized value error? I dont know, but adding blank lines would increase the error message. Well - Life as a novice perl codr is not always easy. TA
OK, a quick update just to describe how I did it.
- Read a complete text file into a scalar
- Split on 0 so we get multiline "blocks" of text and put them into an
+ array
- Go through each element in the list and split it up further into fou
+r blocks.
- The fourth block is what we want. Split it up on \n to get each indi
+vidual line into an array.
- Go through each element (line), check is it empty (eq "") then skip
+to the next
- Finally do our last split, on where we get a "descriptor" and a "des
+cribed"
- Add them to a hash as key/value pair.
Voila :) Only thing that doesnt fit is why would I sometime get an undefined value? regards, ta
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.