in reply to Multiline variables

Please clarify your question, preferably by providing an example of the data and your code to process it.

Replies are listed 'Best First'.
Re^2: Multiline variables
by theantler (Beadle) on Mar 09, 2010 at 10:46 UTC
    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.

        I played some text based adventure games when I was a kid, and I want to re-create one of them and also in a re-imagined way .. Here is my very humble function to init the rooms .. It works now, is very minimum still.
        sub initrooms { my (@ta, %things, $b, @ar, $t, $de, $ex, $th, @a); open (RF, "rooms.txt") or die "could not open datafile: $!"; $/ = undef; $b = (<RF>); $/ = "\n"; @ar = split /0/, $b; foreach (@ar) { ($t, $de, $ex, $th) = split ":", $_; if ($th eq "") { next; } @ta = split "-", $th; %things = @ta; push @a, { TITLE => $t, TEXT => $de, EXITS => $ex, TH +INGS => {%things} }; }; return \@a; }