Brad Whitaker (whitaker) wrote in lj_dev,
Brad Whitaker

[Resolved] Perl Questions...

Hey guys. I'm writing an LJ related script in which I need to keep a fairly large hash of data and have it persistent between page loads. I decided what I'd do is have a bunch of hidden fields of the format one_two_three_four_five which would equat to %DATA{"one"}{"two"}{"three"}{"four"}{"five"} in my hash. So then when a user presses a button to modify the data on the page, I can read back all of the info from the hash that existed when the page was first loaded, mess with it, and spit it back out into the page. I know that description sucked, but I'm hoping you guys understand what I mean. Ask if you have questions.

So I went to write the first subroutine, the one that iters through the %FORM hash and parses the keys for inclusion in the %DATA hash that is being built. At this time ignore the fact that there may be keys in the %FORM hash that are unrelated.

Here's what I have right now:

 $FORM{"bob_jones_rick_rudd"} = "one";
 $FORM{"tree_house_shrub_bush"} = "two";

   sub recurse_hidden {
      my $dataref = shift; # our hashref
      my $segment = shift; # segment of the blah_blah_blah_blah
      my $fullkey = shift; # full part of blah_blah_blah_blah
      if (! $dataref) { return ""; }
      if (! $segment) { return ""; }

         if ($segment =~ /^(\w+?)_.*/) {
            $segment =~ s/^$1_.*//;

         if ($segment !~ /_/) { # we're at the end of the ladder
            $dataref->{$segment} = $FORM{$fullkey};
            return %$dataref->{$segment};

         } else {
            $dataref->{$1} = &merge_form($dataref{$1}, $segment, $fullkey);
            return %$dataref->{$1};


 %DATA = &recurse_hidden(\%DATA);

So basically the problem is that the function doesn't work. I am pretty sure it's something stupid with my referencing, but I'm not quite sure. Would anyone mind taking a look at this and telling me what they think I'm doing wrong? Questions? Answers?


  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded