Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7912249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:33:08+00:00 2026-06-03T13:33:08+00:00

I have a script that I would like to convert to a module and

  • 0

I have a script that I would like to convert to a module and call its functions from a Perl script as I do with CPAN modules now. My question is how would others design the module, I’d like to get some idea how to proceed as I have never written a module before. The script, as written now does this:

1) Sets up logging to a db using am in house module
2) Establishes a connection to the db using DBI
3) Fetch a file(s) from a remote server using Net::SFTP:Foreign
4) Process the users in each file and add the data to the DB

The script currently takes command line options to override defaults using Getopt::Long.

Each file is a pipe delimited collection of user data, ~4000 lines, which goes in to the db, provided the user has an entry in our LDAP directory.

So more to the point:
How should I design my module? Should everything my script currently does be moved into the module, or are there some things that are best left in the script. For example, I was thinking of designing my module, so it would be called like this:

use MyModule;

$obj = MyModule->new; // possibly pass some arguments

$obj->setupLogging;

$obj->connectToDB;

$obj->fetchFiles;

$obj->processUsers;

That would keep the script nice and clean, but is this the best idea for the module? I was thinking of having the script retrieve the files and then just pass the paths to the module for processing.
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T13:33:09+00:00Added an answer on June 3, 2026 at 1:33 pm

    I think the most useful question is “What of this code is going to be usable by multiple scripts?” Surely the whole thing won’t. I rarely create a perl module until I find myself writing the same subroutine more than once.

    At that stage I generally dump it into something called “Utility.pm” until that gathers enough code that patterns (not in the gang of four sense really) start to suggest what belongs in a module with well-defined responsibilities.

    The other thing you’ll want to think about is whether your module is going to represent an object class or if it’s going to be a collection of library subroutines.

    In your example I could see Logging and Database connection management (though I’d likely use DBI) belonging in external modules.

    But putting everything in there just leaves you with a five line script that calls “MyModule::DoStuff” and that’s less than useful.

    Most of the time 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a python script that I would like to add a Shutdown when
I have a script with a factory method that I would like to return
I have a list of 700 words that I would like to convert to
I have a GUI-only vim color scheme that I would like to convert to
I have php scripts that do things like register, login, upload. I would like
I have a user script that would be much more useful if it could
I have a list of image paths in my PHP script that I would
I have a script that will fetch data from server and compose a DIV
I have a script that calls ffprobe, parses its output and outputs it to
I have a Powershell script that uses this PowerShell module . It basically allows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.