Skip to content

Conversation

@mauke
Copy link
Contributor

@mauke mauke commented Mar 15, 2025

... and delete pointless require 5.005 as we already have use 5.008 three lines up.


  • This set of changes does not require a perldelta entry.

... and delete pointless 'require 5.005' as we already have 'use 5.008'
three lines up.
@jkeenan
Copy link
Contributor

jkeenan commented Mar 15, 2025

For the record, can you explain why we should use block eval rather than string eval here (and in some other p.r.s filed today)? Thanks.

@mauke
Copy link
Contributor Author

mauke commented Mar 15, 2025

String eval does two things: It compiles code at runtime, and it catches exceptions (both compile time and runtime errors). Block eval only does one thing: It catches exceptions.

Reasons why you might use string eval:

  1. Metaprogramming, i.e. the code to run is not static, but assembled dynamically.
  2. The code might not compile because it uses syntax only available in newer perl versions, so older perls would throw a parse error.
  3. The code has compile-time effects (e.g. via use or BEGIN) that you would like to delay until runtime instead.

None of these apply here:

  1. The code is a string constant.
  2. Syntactically, there is nothing fancy going on. This code should compile in all perls back to 5.000.
  3. It's all regular (runtime) code.

All we want to do is catch exceptions (specifically, test whether the equivalent of use warnings::register was able to run without errors). All else being equal, block eval is better because it more directly conveys the intent of the code, it is faster (no extra compiler invocation at runtime), and it uses less memory.

@mauke mauke merged commit a453807 into Perl:blead Mar 17, 2025
34 checks passed
@mauke mauke deleted the gumbo-4 branch March 17, 2025 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants