theantler has asked for the wisdom of the Perl Monks concerning the following question:

Dear perl-monks, and novices (like myself), things fit together nicely when working with one-line strings .. but today I found out, that I more easily get confused when working with multiple-line variables .. When you split on one and the split moves onto the next line .. So, I ended up with nesting splits and temporary arrays, and it started getting confusing. Maybe I need to get more routine. I wodner if there is a best practice on how to approach multiline variables? .. Thanks, TA

Replies are listed 'Best First'.
Re: Multiline variables
by jrsimmon (Hermit) on Mar 08, 2010 at 18:54 UTC
    Please clarify your question, preferably by providing an example of the data and your code to process it.
      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

        The uninitialized value error means that you used $key without having assigned it a value. You seem to understand that already.

        Unless you post your code no one can point out the error in your code.