Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • I don't know of any problem with using array references in mod_perl. Can you explain what's giving you trouble? Maybe we can help.
    • Any help is luck for me.
      These three script show what happens.
      -------configuration file(MyConfigTest.pm)--

      package PBB::Packages::MyConfigTest;

      use strict;

      @PBB::Packages::MyConfigTest::ISA = qw(Exporter);
      %PBB::Packages::MyConfigTest::stash = (

          "p_type" => "text/html",
          "p_charset" => "UTF-8",
          "p_theme" => "gnome-default",
          "css_files" => ["aa.js", "bb.js"],
      );

      1;
      -------startup file(mystartup.pl)-------

      #!/usr/bin/perl

      use lib qw(/path/myprj);
      use strict;

      1;
      -------my module file(ControllerTest.pm)--

      package PBB::ControllerTest;

      use vars qw($q $t);
      use vars qw(%stash);
      use Apache2::RequestIO ();
      use Apache2::Const -compile => ':common';
      use CGI qw();
      use CGI::Carp qw(fatalsToBrowser);
      use PBB::Packages::MyConfigTest;
      use Data::Dumper;
      use strict;

      *stash = \%PBB::Packages::MyConfigTest::stash;

      sub handler{
          my $r = shift;
          $q = new CGI;
          print $q->header();
          $t = {};
          @{$t->{stash}}{keys %stash} = values %stash;
          print Dumper($t->{stash});
          push @{$t->{stash}->{css_files}}, "a.js", "b.js";
          print "<br /><br />";
          print Dumper($t->{stash});
          return Apache2::Const::OK;
      }

      1;
      and the follow is the apache config section

      <IfModule mod_perl.c>
          PerlRequire "/path/myprj/mystartup.pl"
          <Location /ptest>
              SetHandler perl-script
              PerlResponseHandler PBB::ControllerTest
              PerlOptions +ParseHeaders
              Order allow,deny
              Allow from all
          </Location>
      </IfModule>
      while browse with http://127.0.0.1/ptest [127.0.0.1] ,I see the result:

      $VAR1 = { 'p_type' => 'text/html', 'css_files' => [ 'aa.js', 'bb.js', 'a.js', 'b.js', 'c.js', 'a.js', 'b.js', 'c.js', 'a.js', 'b.js', 'c.js' ], 'p_theme' => 'gnome-default', 'p_charset' => 'UTF-8' };

      $VAR1 = { 'p_type' => 'text/html', 'css_files' => [ 'aa.js', 'bb.js', 'a.js', 'b.js', 'c.js', 'a.js', 'b.js', 'c.js', 'a.js', 'b.js', 'c.js', 'a.js', 'b.js', 'c.js' ], 'p_theme' => 'gnome-default', 'p_charset' => 'UTF-8' };

      What's wrong with me?

      Regards.
      --
      use Perl qw(others us);
      • I don't understand. Didn't you want the array to expand? If you were trying to replace it, just set it directly instead of using push:

        $t->{stash}->{css_files} = ['a.js', 'b.js'];

        There are several other things in this code that I would suggest changing, but this forum isn't the best place to do a code review. If you'd like more advice on your code, please post it on the mod_perl mailing list, or on http://perlmonks.org/ [perlmonks.org].