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 8214209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:23:05+00:00 2026-06-07T11:23:05+00:00

I want to separate all the common subroutines in another file to save up

  • 0

I want to separate all the common subroutines in another file to save up some space and to tidy up each files. Then just use require() to call a subroutine.

for ex.

sub greet{
     print "Hi there\n";
}

which I added and called in Script1.pl, Script2.pl and Script3.pl.

What are the pro’s and con’s on separating subroutines to another file?

I’m sorry for my grammar. Hope you’d help me understand.

  • 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-07T11:23:07+00:00Added an answer on June 7, 2026 at 11:23 am

    Whenever you have code that is used by more than one script, it generally ought to be split into a library, as you have described. There are many ways to do this, and each has its own advantages and disadvantages which are beyond the scope of your specific question.

    So to address your specific question as to pros and cons of moving functionality into a library, lets start with

    Pros

    1. Because you have less duplicate code it is easier to
      • Debug your code (fewer places for bugs to exist)
      • Update your code (you don’t have to edit the same functionality in 10 places)
    2. It makes it easier to share your library functions with other people, or just other projects
    3. It encourages better design, by making you think modularly
    4. Saves space (a pretty minor point, with modern storage media)

    Cons

    1. It’s harder to distribute your code–you must make sure you distribute all required files as well.
    2. It’s not as easy to see your entire code at once–only an issue for small projects, where you even have the option of fitting the entire project on the screen (or in your head) at once

    General rule of thumb: Except for very small and/or self-contained projects, use libraries.

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

Sidebar

Related Questions

I want to compile some C++ files and I absolutely have to put all
I have the simplest code that I want to separate in three files: Header
Trying to implement 3-layer (not: tier, I just want to separate my project logically,
I want to set up a separate listener to each switch in each of
I want to be able to separate each item in a listbox with a
I want to put my html navigation in a separate php file so when
i want to to persist some filenames for the user (e.g. recent files). Let's
I have a big javascript file common.js with all my functions and stuff...and i
I have 8 separate tables. Each table has id, a datetime field and some
I want this text all on one line, not spaced on two sepearate lines.

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.