What's the best way to open and read a file in Perl?

前端 未结 12 1976
醉话见心
醉话见心 2020-11-27 13:11

Please note - I am not looking for the \"right\" way to open/read a file, or the way I should open/read a file every single time. I am just interested to find out what way m

12条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-27 13:17

    The || operator has higher precedence, so it is evaluated first before sending the result to "open"... In the code you've mentioned, use the "or" operator instead, and you wouldn't have that problem.

    open INPUT_FILE, "<$input_file"
      or die "Can't open $input_file: $!\n";
    

提交回复
热议问题