Chinaunix首页 | 论坛 | 博客
  • 博客访问: 939652
  • 博文数量: 146
  • 博客积分: 3321
  • 博客等级: 中校
  • 技术积分: 1523
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-29 10:32
文章分类

全部博文(146)

文章存档

2014年(2)

2013年(5)

2012年(4)

2011年(6)

2010年(30)

2009年(75)

2008年(24)

分类: Python/Ruby

2012-06-22 12:21:00

文件句柄赋值给hash变量不能直接使用,可以使用的两种方法是:

点击(此处)折叠或打开

  1. #!/usr/bin/perl -w
  2. use Data::Dumper;

  3. my %FH;
  4. open ($FH{nt}, ">>mod.log");

  5. my $fh;
  6. $fh    =    $FH{nt};
  7. print $fh "hello";
  8. print {$FH{nt}} "hello";
$perldoc -f print
      print FILEHANDLE LIST
       print LIST
       print   Prints a string or a list of strings.  Returns true if successful.  FILEHANDLE may be a scalar variable name, in which case the variable
               contains the name of or a reference to the filehandle, thus introducing one level of indirection.  (NOTE: If FILEHANDLE is a variable and
               the next token is a term, it may be misinterpreted as an operator unless you interpose a "+" or put parentheses around the arguments.)  If
               FILEHANDLE is omitted, prints by default to standard output (or to the last selected output channel--see "select").  If LIST is also
               omitted, prints $_ to the currently selected output channel.  To set the default output channel to something other than STDOUT use the
               select operation.  The current value of $, (if any) is printed between each LIST item.  The current value of "$\" (if any) is printed
               after the entire LIST has been printed.  Because print takes a LIST, anything in the LIST is evaluated in list context, and any subroutine
               that you call will have one or more of its expressions evaluated in list context.  Also be careful not to follow the print keyword with a
               left parenthesis unless you want the corresponding right parenthesis to terminate the arguments to the print--interpose a "+" or put
               parentheses around all the arguments.

               Note that if you're storing FILEHANDLEs in an array, or if you're using any other expression more complex than a scalar variable to
               retrieve it, you will have to use a block returning the filehandle value instead:

                   print { $files[$i] } "stuff\n";
                   print { $OK ? STDOUT : STDERR } "stuff\n";

阅读(5031) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~