+ -
当前位置:首页 → 问答吧 → 请教一个标量转换为数组的问题

请教一个标量转换为数组的问题

时间:2010-09-07

来源:互联网

请教各位大侠:
  1. #!/usr/bin/perl -w
  2. use strict;
  3. sub read_file
  4. {
  5.         my (%conf_hash);
  6.         open(CONFFILE, "1.conf") || die "connot open 1.conf: $!";
  7.         while (<CONFFILE>) {
  8.                 next if (m/^[ \t]*$/);        
  9.                 chomp;                                      
  10.                 s/#.*//;                                      
  11.                 s/^[\b\t]+//;                        
  12.                 %conf_hash = ( %conf_hash, split(/=/) );     
  13.         }
  14. return %conf_hash;
  15. }

  16. my %conf = read_file();
  17. my $man = "$conf{man}";
  18. my @man2 = $man;
  19. foreach (@man2)
  20. {
  21.             print "$_\n";
  22. }
复制代码
----------------------------------------------------
$  ./1.pl
$ "张三","李四","王五"
$ cat 1.conf ###配置文件
#配置文件
man="张三","李四","王五"
----------------------------------------------------
请问有没有办法将从配置文件读出来的内容 赋予给一个数组呢?或以数组形式展现。谢谢

作者: 小渔村   发布时间: 2010-09-07

用split函数··

作者: wfnh   发布时间: 2010-09-07