Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: using a variable with require

by GrandFather (Saint)
on Jun 22, 2022 at 21:25 UTC ( [id://11144960]=note: print w/replies, xml ) Need Help??


in reply to Re^2: using a variable with require
in thread using a variable with require

You can do that in a very light weight way by creating a package for each feed type. They can be in a single file or multiple files or even the main file. If not in the main file you can use or require as suits your purpose then create an instance of the appropriate type. Consider:

use strict; use warnings; package FetchOne; sub new { my ($class, %params) = @_; return bless\%params, $class; } sub type { return 'Fetch type One'; } package FetchTwo; sub new { my ($class, %params) = @_; return bless\%params, $class; } sub type { return 'Fetch type Two'; } package main; my $type = 'Two'; my $obj = "Fetch$type"->new(); print $obj->type();

Prints:

Fetch type Two
Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-20 08:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found