diff options
author | Dan Book <grinnz@grinnz.com> | 2019-07-09 01:36:32 -0400 |
---|---|---|
committer | Nicolas R <nicolas@atoomic.org> | 2020-01-02 16:42:14 -0700 |
commit | 601390ce200db31ae8eecba5649a8c1f2e14ca3d (patch) | |
tree | 979e6bbd47c89050cf4418d07d2b09200db80ea0 /pod/perlvar.pod | |
parent | c43b10468460609a13d1156387b9337503b5d828 (diff) | |
download | perl-601390ce200db31ae8eecba5649a8c1f2e14ca3d.tar.gz |
recommend numeric comparisons for $]
Diffstat (limited to 'pod/perlvar.pod')
-rw-r--r-- | pod/perlvar.pod | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/pod/perlvar.pod b/pod/perlvar.pod index bce1b5d64f..94fa73028b 100644 --- a/pod/perlvar.pod +++ b/pod/perlvar.pod @@ -437,12 +437,11 @@ is the subversion / 1e6. For example, Perl v5.10.1 would be "5.010001". This variable can be used to determine whether the Perl interpreter executing a script is in the right range of versions: - warn "No PerlIO!\n" if $] lt '5.008'; + warn "No PerlIO!\n" if "$]" < 5.008; -When comparing C<$]>, string comparison operators are B<highly -recommended>. The inherent limitations of binary floating point -representation can sometimes lead to incorrect comparisons for some -numbers on some architectures. +When comparing C<$]>, numeric comparison operators should be used, but the +variable should be stringified first to avoid issues where its original +numeric value is inaccurate. See also the documentation of C<use VERSION> and C<require VERSION> for a convenient way to fail if the running Perl interpreter is too old. @@ -453,9 +452,10 @@ object, which allows more flexible string comparisons. The main advantage of C<$]> over C<$^V> is that it works the same on any version of Perl. The disadvantages are that it can't easily be compared to versions in other formats (e.g. literal v-strings, "v1.2.3" or -version objects) and numeric comparisons can occasionally fail; it's good -for string literal version checks and bad for comparing to a variable -that hasn't been sanity-checked. +version objects) and numeric comparisons are subject to the binary +floating point representation; it's good for numeric literal version +checks and bad for comparing to a variable that hasn't been +sanity-checked. The C<$OLD_PERL_VERSION> form was added in Perl v5.20.0 for historical reasons but its use is discouraged. (If your reason to use C<$]> is to |