Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Perl - Header files?

Options
  • 16-11-2003 8:33pm
    #1
    Registered Users Posts: 2,518 ✭✭✭


    I'm throwing together a simple web application in perl with a mysql backend.

    Is there a way to put the database connection details, ie: dbname, username and password in a header file to include at the top of each script?, similar to phps include() and require() functions ?


Comments

  • Registered Users Posts: 2,518 ✭✭✭Hecate


    I've given require() a go but it doesnt seem to play nice when CGI is involved, just get a lot of error 500s...


  • Registered Users Posts: 1,186 ✭✭✭davej


    You can include it at the top of your file using:

    require "/path/function.pl";

    Make sure the path to the filename is correct, the root of your site might be different to what you think. Check the error logs to see why it's failing!

    davej


  • Closed Accounts Posts: 304 ✭✭Zaltais


    'use' is a bit more powerful and flexible than 'require', but both do almost the same job.

    If you are going to be including a number of configuration files you (e.g. one for configuration settings and one for common functions) you should consider using the 'lib' pragma in conjunction with use.

    This way you get away with doing the following:

    use lib '/full/path/to/perl/modules';
    use My::Module1;
    use My::Module2;

    rather than

    require '/full/path/to/perl/modules/My/Module1.pm';
    require '/full/path/to/perl/modules/My/Module2.pm';

    You'll probably also need to look at

    Exporter for use in the modules themselves....


Advertisement