Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: preferred loading of XS modules

by CountZero (Bishop)
on Nov 25, 2015 at 20:35 UTC ( [id://1148622]=note: print w/replies, xml ) Need Help??


in reply to preferred loading of XS modules

Module Text::CSV will take care of it automatically, but in general you could use the following:
my @modules=qw/Module::One_XS Module::Two_PP/; foreach my $module (@modules) { eval qq| use $module |; last unless $@ }

Update: As choroba astutely remarked the "next if $@" should be "last unless $@"

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics

Replies are listed 'Best First'.
Re^2: preferred loading of XS modules
by choroba (Cardinal) on Nov 25, 2015 at 21:01 UTC
    Didn't you mean
    last unless $@;

    ? Your code tries to use both the modules regardless of their availability.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      Indeed, you are right.

      Funny enough, my initial code had the "last unless $@" and then I changed it. Silly me.

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      My blog: Imperial Deltronics
      my

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (2)
As of 2024-04-25 19:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found