小编Prz*_*mek的帖子

我如何以递归方式读出Perl中的目录?

我想以递归方式读出一个目录,以便在带有Template :: Toolkit的HTML-Page中打印数据结构.但我在如何以一种可以轻松阅读的形式保存路径和文件.

我的想法是这样开始的

sub list_dirs{

     my ($rootPath) = @_;
     my (@paths);

     $rootPath .= '/' if($rootPath !~ /\/$/);

     for my $eachFile (glob($path.'*'))
     {

         if(-d $eachFile)
         {
              push (@paths, $eachFile);

              &list_dirs($eachFile);
          }
          else
          {
              push (@files, $eachFile);
          }
     }

 return @paths;
}
Run Code Online (Sandbox Code Playgroud)

我怎么能解决这个问题?

directory treeview recursion perl

11
推荐指数
3
解决办法
2万
查看次数

如何使用Template Toolkit从数组中获取元素?

我有一系列路径,我想用Template Toolkit读出来.如何访问此数组的数组元素?情况是这样的:

my @dirs;
opendir(DIR,'./directory/') || die $!;
@dirs = readdir(DIR);
close DIR;
$vars->{'Tree'} = @dirs;
Run Code Online (Sandbox Code Playgroud)

然后我像这样调用模板页面:

$template->process('create.tmpl', $vars) 
   || die "Template process failed: ", $template->error(), "\n";
Run Code Online (Sandbox Code Playgroud)

在这个模板中,我想在数组中创建一个目录树.我怎样才能访问它们?

我的想法是从foreach像这样的模板开始

[% FOREACH dir IN Tree.dirs %]
$dir
[% END %]
Run Code Online (Sandbox Code Playgroud)

arrays perl template-toolkit

5
推荐指数
1
解决办法
3064
查看次数

如何在Perl hash-of -hes中获取二级密钥?

我需要在哈希中获取某个键的所有值.哈希看起来像这样:

$bean = {
     Key1 => {
               Key4 => 4,
               Key5 => 9,
               Key6 => 10,
             },
     Key2 => {
               Key7 => 5,
               Key8 => 9,
             },
};
Run Code Online (Sandbox Code Playgroud)

我只需要值Key4,Key5Key6为例子.其余的不是兴趣点.我怎么能得到价值观?

更新:所以我没有%bean我只是添加这样的值$bean:

 $bean->{'Key1'}->{'Key4'} = $value;
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助.

perl hash perl-data-structures

2
推荐指数
1
解决办法
7857
查看次数

如何在perl中扩展ini文件

我需要在perl中扩展一个INI文件.我有一个给定的INI-File,我可以用Config :: IniFiles读取,但我也需要为该INI文件添加参数.

例如,文件看起来像

[section1]
param1=val1
param2=val2

[section2]
param1=val3
param2=val4
Run Code Online (Sandbox Code Playgroud)

我需要在这些部分添加参数

[section1]
param1=val1
param2=val2
param3=val5

[section2]
param1=val3
param2=val4
param3=val6
Run Code Online (Sandbox Code Playgroud)

我不知道CPAN中是否有模块.到目前为止还没找到一个可以完成工作的人.感谢您解决此问题的任何想法!

perl ini

2
推荐指数
1
解决办法
707
查看次数

如何在Perl中阅读使用POST发送的URL-Data?

我正在尝试读出从页面中的表单发送到我的Perl脚本的POST数据.我用Google搜索并发现:

read(STDIN, $param_string, $ENV{'CONTENT_LENGTH'})
Run Code Online (Sandbox Code Playgroud)

读取整个Data-String,并以.的形式将整个字符串写入$ param_string

Param1=Value1&Param2=Value2&Param3=Value3
Run Code Online (Sandbox Code Playgroud)

通过将它拆分到正确的位置,我得到了必要的数据.

但我想知道为什么我的$ param_string是空的.

当我用GET尝试整个事情时:

$param_string = $ENV{'QUERY_STRING'};
Run Code Online (Sandbox Code Playgroud)

一切正常.有人有想法吗?

forms perl post cgi query-string

0
推荐指数
1
解决办法
2760
查看次数