in reply to Can't seem to use an AoH with Template::Toolkit

In short, the problem is too much magic. When you call $cgi->Vars, you don't get a normal hashref. Instead, you get a ref to a tied hash, with different behavior from a normal hash. Try copying the params you want into a normal hash instead.

Replies are listed 'Best First'.
Re^2: Can't seem to use an AoH with Template::Toolkit
by tinita (Parson) on Jan 29, 2007 at 08:33 UTC
    When you call $cgi->Vars, you don't get a normal hashref.
    yes, in scalar context. in list context, you get a 'normal' hash.
    my %vars = $cgi->Vars;
      You mean array context list context, but yes, that does give you a list that you can make into your own normal hash. Here's the sub definition:
      sub Vars { my $q = shift; my %in; tie(%in,CGI,$q); return %in if wantarray; return \%in; }
Re^2: Can't seem to use an AoH with Template::Toolkit
by talexb (Chancellor) on Jan 29, 2007 at 13:42 UTC

    Maybe I've mis-understood you -- I made the code less fancy and used a hash instead of a hashref, as shown below, and got the sme result.

    for ( 1..9 ) { my $last = "last_name$_"; my $first = "first_name$_"; my %h; if ( length($vars->{$last}) && length($vars->{$last}) ) { $h{'last_name'} = $vars->{$last}; $h{'First_name'} = $vars->{$first}; } else { # Leave a blank one at the end. $h{'last_name'} = ''; $h{'First_name'} = ''; last; } push ( @reg_array, \%h ); }

    I guess I don't understand your answer.

    I'm able to get the information from $vars just fine, but it seems putting it back onto the form is a problem.

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

      In your original code, you get a hashref back from $cgi->Vars, and then you try to put @reg_array into it as if it were a normal hashref. That would work, except that $vars that comes back from $cgi->Vars is not a hashref, but rather a tied variable that CGI generated.

      I can't tell if the code you show here still has that problem because you didn't show that part. If it does, a quick fix would be to change that line where you call $cgi->Vars to this:

      my %vars = $cgi->Vars; my $vars = \%vars;