Perl assignment with a dummy placeholder

后端 未结 4 2252
北恋
北恋 2020-12-18 17:51

In other languages I\'ve used like Erlang and Python, if I am splitting a string and don\'t care about one of the fields, I can use an underscore placeholder. I tried this

4条回答
  •  臣服心动
    2020-12-18 18:27

    And just to explain why you get the particular error that you see...

    _ is a internal Perl variable that can be used in the stat command to indicate "the same file as we used in the previous stat call". That way Perl uses a cached stat data structure and doesn't make another stat call.

    if (-x $file and -r _) { ... }
    

    This filehandle is a constant value and can't be written to. The variable is stored in the same typeglob as $_ and @_.

    See perldoc stat.

提交回复
热议问题