Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: using a variable to specify which perl module to use

by flounder99 (Friar)
on Jul 15, 2003 at 18:35 UTC ( [id://274512]=note: print w/replies, xml ) Need Help??


in reply to using a variable to specify which perl module to use

This sounds like a good application of a subclass;
create a MyText.pm:
package MyText; sub init_XS { my $class = shift; my $usexs = shift; if ($usexs) { eval { use Text::CSV_XS; @ISA = ('Text::CSV_XS'); } } else { eval { use Text::CSV; @ISA = ('Text::CSV'); } } } 1;
Then in your program do this:
use MyText; my $usexs = 1; #decide whether to use XS MyText->init_XS($usexs); my $csvobj = MyText->new(); #Text::CSV_XS->new gets called if $usexs is true. #Text::CSV->new gets called if $usexs is false. #do stuff with $csvobj

--

flounder

Log In?
Username:
Password:

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

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

    No recent polls found