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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:55:46+00:00 2026-05-21T19:55:46+00:00

I was wondering, do all of the modules I use in a perl script

  • 0

I was wondering, do all of the modules I use in a perl script need to be at the beginning of the a script?

The reason I am wonder is I have a place in my script where it “splits” one way is the script connects with SSH using authorized keys. The other way is the script connects with SSH using a username and password. I am using the modules Net::OpenSSH to do SSH. According the cpan doc if I want all username and password authentication I need IO::Pty.

Well I wanted to only check the requirement of IO::Pty if the subroutine set to login with username and password is triggered. Is that possible? To load the module only if a certain subroutine is triggered?

  • 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-05-21T19:55:47+00:00Added an answer on May 21, 2026 at 7:55 pm

    The use IO::Pty; line means the following to Perl:

    BEGIN {
        require IO::Pty;
        IO::Pty->import;
    }
    

    So first Perl loads the module with require (which will die if it can’t find the module), and then it calls the ->import method if it exists.

    You can turn this into a runtime conditional as follows:

     if (eval {require IO::Pty}) {
         # IO::Pty->import;
         # or use fully qualified names: IO::Pty::some_sub(...);
         # in both cases, the parenthesis after the subroutine are required, since
         # the import is not visible at compile time
     } else {
         # run other code, or throw an error with `die`
     }
    

    Packages import into other packages, not into other scopes, so the import will be visible outside of the subroutine that performs it. It is probably best to skip the import all together and just use fully qualified names.

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

Sidebar

Related Questions

Hey all, I am wondering what the best way to do the following is:
I have been wondering how to put all the stored procedures on a SQL
I was wondering how can I programmatically copy all the discussion items from one
I have a C# application. Currently all modules are written in .NET 2 and
I have a multi-module (maven) spring build. All the modules publish some beans, and
I'm just wondering if it's possible to use one regular expression to match another,
Just wondering about this... I have several separate javascript files, that all contain code
I'm wondering how to setup a more specific logging system. All my tasks use
Hullo all, Wondering if there are any Java hackers who can clue me in
Hey all. I'm wondering how to implement a timeout event in the System.Windows.Forms.Webbrowser control?

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.