+ -
当前位置:首页 → 问答吧 → 求解变量作为句柄问题

求解变量作为句柄问题

时间:2010-09-29

来源:互联网

  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;

  4. my %hash=(
  5.         ESERU        =>        "es-eser.up",
  6.         ESFLU        =>        "es-fler.up",
  7.         ESPBU        =>        "es-pber.up",
  8. );

  9. foreach my $fh (keys %hash) {
  10.         open $fh,"$hash{$fh}";
  11.         while (<$fh>) {
  12.                 .......
  13.         }
  14.         close;
  15. }
复制代码
出现错误:Can't use string ("ESERU") as a symbol ref while "strict refs" ,请教各位

作者: frewise   发布时间: 2010-09-29

少了 Mode

作者: Mr-Summer   发布时间: 2010-09-29

不能这样用。

可以open $fh,也可以open FH,但是不能$fh='FH';open $fh

作者: yybmsrs   发布时间: 2010-09-29

use strict;
use warnings;
no strict 'refs';

.............

作者: toniz   发布时间: 2010-09-29