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

I am having a weird issue when assigning data to a hash ref from the output from Data::Formvalidator in a catalyst app. The problem is when I print the values of the hash_ref and compare against what came back from Data::Formvalidator they differ and I don't see why they would.

Here is what I am doing in my Code:

my $data = { name => $results->valid('name'), url => $results->valid('url'), gagline => $results->valid('gagline'), shortdescript => $results->valid('shortdescript'), descript => $results->valid('descript'), stable => $results->valid('stable'), dev => $results->valid('dev'), stablerelease => $results->valid('stablerelease'), devrelease => $results->valid('devrelease'), active => $results->valid('active'), schangelog => $results->valid('schangelog'), dchangelog => $results->valid('dchangelog'), }; $c->log->debug('Gag Line 1: ' . $results->valid('gagline')); $c->log->debug('Short Description 1: ' . $results->valid('shortdescrip +t')); $c->log->debug('Description 1: ' . $results->valid('descript')); $c->log->debug('Gag Line 2: ' . $data->{gagline}); $c->log->debug('Short Description 2: ' . $data->{shortdescript}); $c->log->debug('Description 2: ' . $data->{descript});
From the Catalyst server debug log I see the following output:
[debug] Gag Line 1: [debug] Short Description 1: A Custom CMS [debug] Description 1: Ickarus is a custom CMS made by Shimazu Labs fo +r Shimazu Labs. [debug] Gag Line 2: shortdescript [debug] Short Description 2: [debug] Description 2:
Anyone have an idea has to how this is happening?

Replies are listed 'Best First'.
Re: Weird hash ref variable issue
by keszler (Priest) on Oct 23, 2011 at 19:37 UTC

    According to Data::FormValidator::Results the ->valid method "...returns an hash reference which contains the valid fields as keys and their input as values". That seems to indicate that you could replace your my $data = {painful enumeration }; with my $data = $results->valid;. Then, use Data::Dumper; print Dumper($data); will show if any of the results are anything other than the scalars you expect.

    update - right, Catalyst. Make that use Data::Dumper; $c->log->debug("\$data:\n".Dumper($data));

      I was doing the very long and painful enumeration to try and figure out how/why those values were being switched around. Ideally I would be using my $data = $results->valid, using the $results->valid hash_ref directly was throwing errors with DBIx which is why I ended up building the other hash_ref in the first place.

      Update: Turns out that dumping the $results->valid variable directly into the $data hash_ref everything works out just fine. I guess I was doing something wrong before

Re: Weird hash ref variable issue
by jethro (Monsignor) on Oct 23, 2011 at 19:17 UTC

    Don't know the module, but your results would suggest that for example $results->valid('url') is returning an array instead of a scalar.

    I would suggest using Data::Dumper and dumping join('',Dumper($results->valid('url'))); (or even the whole valid structure) into the log to check