Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

compilation error on 5.8 with $^V gt 'v5.10.0'

by gabrielsousa (Sexton)
on Apr 03, 2018 at 09:22 UTC ( #1212234=perlquestion: print w/replies, xml ) Need Help??

gabrielsousa has asked for the wisdom of the Perl Monks concerning the following question:

is there a way to not check for a code if the perl isnt GT 5.10 ?
if ( $^V gt 'v5.10.0' ) { @diff = grep { ! ({ $_, 0 } ~~ @inst) } @insttab; } else { @hdiff{ @insttab } = undef; delete @hdiff{ @inst }; @diff = keys %hdiff; }

Replies are listed 'Best First'.
Re: compilation error on 5.8 with $^V gt 'v5.10.0'
by hippo (Chancellor) on Apr 03, 2018 at 09:40 UTC

    Use eval to avoid parsing too-recent code at compile time.

    Or just avoid using smartmatch entirely, of course. This is the way I would choose.

Re: compilation error on 5.8 with $^V gt 'v5.10.0'
by ikegami (Pope) on Apr 03, 2018 at 10:44 UTC
    $] > 5.010

    By the way, it seems very weird to check if Perl's version is greater than a constant. I can see < and ≥, but not >.

      Oops, that still leaves the issue of ~~. Well, seeing as it's a broken experimental feature, best if you simply avoid it!

      Not only that, your smart-match version is far less efficient. Use one of the following:

      # Unordered my %diff; @diff{ @insttab } = (); delete @diff{ @inst }; my @diff = keys %diff;
      or
      # Ordered my %in_inst; @in_inst{ @inst } = (); my @diff = grep { !exists($in_inst{$_}) } @insttab;

      Both are O(N+M) (as opposed to the O(N*M) smartmatching approach).


      Generally speaking, you'd want two different modules with the same interface in that situation. Simply load the correct module using if (the module).

A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1212234]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (1)
As of 2021-09-28 18:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?