• Reference Basic in Perl


    Making References

    References can be created in several ways.

    By using the backslash operator on a variable, subroutine, or value. (This works much like the & (address-of) operator in C.) This typically creates another reference to a variable, because there's already a reference to the variable in the symbol table. But the symbol table reference might go away, and you'll still have the reference that the backslash returned. Here are some examples:

    1. $scalarref = \$foo;
    2. $arrayref = \@ARGV;
    3. $hashref = \%ENV;
    4. $coderef = \&handler;
    5. $globref = \*foo;

    Using References

    That's it for creating references. By now you're probably dying to
    know how to use references to get back to your long-lost data. There
    are several basic methods.

    1. Anywhere you'd put an identifier (or chain of identifiers) as part of a

      variable or subroutine name, you can replace the identifier with a
      BLOCK returning a reference of the correct type. In other words, the
      previous examples could be written like this:

      1. $bar = ${$scalarref};
      2. push(@{$arrayref}, $filename);
      3. ${$arrayref}[0] = "January";
      4. ${$hashref}{"KEY"} = "VALUE";
      5. &{$coderef}(1,2,3);
      6. $globref->print("output\n"); # iff IO::Handle is loaded
  • 相关阅读:
    Python获取 东方财富 7x24小时全球快讯
    Elasticsearch 环境配置
    可执行jar包与依赖jar包
    IDEA注释模板
    CKEditor
    解决让浏览器兼容ES6特性
    asp.net一个非常简单的分页
    Asp.Net真分页技术
    jsp选项卡导航实现——模板
    nodejs类比Java中:JVM
  • 原文地址:https://www.cnblogs.com/taoxu0903/p/1559299.html
Copyright © 2020-2023  润新知