Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl version string: why use EVAL EXPR?

Tags:

I just took notice to this generated by Catalyst.pl. It is obviously some sort of unannotated hack. What is the advantage of setting up a version string like this? I can't even figure out what they're trying to do.

our $VERSION = '0.01'; $VERSION = eval $VERSION; 
like image 448
NO WAR WITH RUSSIA Avatar asked Sep 03 '10 20:09

NO WAR WITH RUSSIA


People also ask

Why we use eval in Perl?

eval in all its forms is used to execute a little Perl program, trapping any errors encountered so they don't crash the calling program.

What does eval return in Perl?

The eval block is parsed with the rest of the code and its return value is a reference to the array @a . That reference is assigned to $ttt . While the eval block goes out of scope, @a still has a non-zero reference count (thanks to $ttt ) so it still exists.

What is $@ in Perl?

$@ The Perl syntax error or routine error message from the last eval, do-FILE, or require command. If set, either the compilation failed, or the die function was executed within the code of the eval.


1 Answers

Version numbers are complex in Perl. Here's an excellent overview for those looking for the gory details. It might surprise you how many subtle ways there are to get things wrong...

The direct answer to your question though, is that different things expect different formats. For CPAN, you care about development versions for example, as a string. For runtime, you care about them as a number.

Consider the case of $VERSION = "0.01_001". eval converts it to the number 0.01001 correctly.

like image 116
szbalint Avatar answered Oct 19 '22 17:10

szbalint