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

  • Home
  • SEARCH
  • 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 7704223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:38:15+00:00 2026-05-31T23:38:15+00:00

I have a CGI interface that calls a Perl plugin. Those scripts are located

  • 0

I have a CGI interface that calls a Perl plugin. Those scripts are located in different folders and the Perl one is supposed to read an XML file that is located in another folder. To make it simple I give you an example:

/a/b/cgi-bin/test.cgi # calls test.pl
/e/plugins/test.pl # reads config.xml
/e/etc/config.xml

Now I don’t know how to make the Perl plugin to read the config file. Ofcourse I can’t write the path on the script because tomorrow I may change the location of this file. I tryed using Cwd and abs_path on test.pl but this method returns the “running” path when instead I want the “location” path of test.pl so I can modify it in order to build the config.xml path. Any ideas?

EDIT: Using realpath instead of abspath solved my problem, or at least it seems so, I’ll do more tests.

EDIT2: Ok realpath works but now I have another problem… The Perl plugin uses some additional packages that I made but ofcourse now writing use MyPackage; doesn’t work anymore because it looks on the wrong folder… Is there a way to modify the environment variable? I don’t know something that will avoid me from changing thousands lines of code.

EDIT3: Ok solved that too somehow, I guess I will just install my packages in the INC folder so I don’t have to mess up with my code anymore.

  • 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-31T23:38:16+00:00Added an answer on May 31, 2026 at 11:38 pm

    The following function will return the path of an used()ed package:

    use Cwd qw/abs_path/; 
    
    sub get_module_folder {
      my $mkey = shift;
      $mkey =~ s|\:\:|/|g;
      $mkey .= '.pm';
      my $mpath = $INC{$mkey};
      $mpath =~ s|/[^/]+$||;
      return abs_path($mpath);
    }
    

    So if test.pl implements a package, say Plugin::Foo, then just call it as:

    use Plugin::Foo;
    open my $f, '<', get_module_folder('Plugin::Foo').'/../etc/config.xml'
      or die "can't open config file for reading: $!";
    

    (Assuming that I’ve understood your folder structure correctly).

    Updated: to use abs_path.

    I often include this method in my own modules (replacing shift with __PACKAGE__) so that they can find any config/data they require.

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

Sidebar

Related Questions

I have a perl cgi script that's fairly resource intensive (takes about 2 seconds
I currently have a Perl CGI script that parses incoming XML requests using XML::Simple
I have a CGI script that prints the following on stdout: print Status: 302
I have a cgi c++ program on bluehost that works when you manually feed
Why cgi scripts have to stay in cgi-bin folder ? What is the difference
I have a small cgi script that fetches and validates a configuration file for
CGI scripts should have access to a list of environment variables set by the
I have this Perl script sitting in the cgi-bin folder of my Apache server:
I have a CGI script that uses an old database driver that is no
I have a CGI based form that I am working with and I would

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.