in reply to Retrieving "msgs" values from Data::FormValidator

Thanks Cees ... I believe I'm getting closer to understanding this .... I used Data::Dumper as suggested, and the output was:
$VAR1 = { 'three' => '<span style="color:red;font-weight:bold"><span i +d="dfv_errors">* Missing</span></span>', 'two' => '<span style="color:red;font-weight:bold"><span id= +"dfv_errors">* Missing</span></span>' };
This appears to be the default outpur from D::FV. ... it seems the problem I'm having is not knowing how to call the elements from the hash above.

It appears that the keys of the hash are the field names of the required fields that were submitted as blanks from the form.

And it also appears that I should be able to call the items from the above hash and associate them to the $results->(missing) array .... that is if I knew how to call the hash value ...

It looks to these rookie eyes that Data::Dumper shows the hash name as "$VAR1" ... and I'm guessing that in order for me to call the hash values, I need to know the hash name ???

I've been trying all kinds of combinations:

print $results->msgs(); print $results->msgs(you name it); print $results->msgs(I've tried it);
but I still keep getting a damn hash reference, and no data. Frustrating, to say the least ;)

Replies are listed 'Best First'.
Re: Re: Retrieving "msgs" values from Data::FormValidator
by cees (Curate) on Dec 21, 2003 at 00:29 UTC

    I'm glad to see that you are on the right track. What you need to learn now is how to deal with references and data structures in perl. I would recommend that you read the references tutorial here on PerlMonks to get you familiar with how to access data structures in perl.

    Now, back to D::FV. From the docs it says that the msgs method returns a hash reference. So in order to access the data you will need to know how to de-reference that hash. The folowing code should be able to print out your messages:

    my $messages = $results->msgs(); # $messages now contains a hashref # The arrow operator de-references the hashref print "input two: ", $messages->{two}, $/; print "input three: ", $messages->{three}, $/; # Or de-reference it first and then print my %messages_hash = %$messages; print "input two: ", $messages_hash{two}, $/; print "input three: ", $messages_hash{three}, $/; # Or print out everything in messages while (my($key, $value) = each %$messages) { print "input $key: $value$/"; }

    I have not tested the above code, but if msgs does return a hash reference then it should work.

    Hope this helps...

    - Cees

      my $messages = $results->msgs(); # $messages now contains a hashref
      I guess that's where my brain cramp was .... following your example allowed me to access the values - thanks very much.

      I think the trouble I'm having coming up to speed is wrapping my brain around the various forms of data ... for some reason, items such as %$message are still un-intuitive for me.

      >I would recommend that you read the references tutorial here on PerlMonks to get you familiar with how to access data structures in perl.

      I certainly will (probably numerous times) ... sometimes it's difficult to know what to read when you don't know what you need ;).

      I've got a feeling that when it finally becomes clear, it will be in a threshold way, and I'll find myself wondering why it took me so long to grasp it.