LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-17-2003, 10:56 AM   #1
mrtwice
Member
 
Registered: Feb 2002
Distribution: xubuntu 8.10
Posts: 225

Rep: Reputation: 31
need perl fuction like c #include statement for header file


I have several different perl programs that use the same initial variables for configuration purposes. I have all of these variables in a configuration file called config.pl.

config.pl:
Code:
#mon config settings

our $mondir = "/opt/mon";
our $mapdir = "$mondir/test/maps";
then in my program I require the file and use the variables:

prog.pl
Code:
#!/usr/bin/perl -w
#
require "./config.pl";


#open directory and store files in array
opendir( MAPS,"$mapdir");                            #mapdir is correct from required file.
my @maps = grep !/^\.\.?$/,readdir MAPS;
closedir(MAPS);
This actually works great. The problem is that I would like to
Code:
use strict
. when I do, all of my included variables need to be declared which is a pain. Is there a way to do both of these things? I have looked into packages somewhat but that seems like an aweful lot of work just to include a couple variables. Thanks!
 
Old 06-17-2003, 02:11 PM   #2
llama_meme
Member
 
Registered: Nov 2001
Location: London, England
Distribution: Gentoo, FreeBSD
Posts: 590

Rep: Reputation: 30
I think there's a command line option for the Perl interpreter that pipes the code through the C preprocessor first, so you could literally use #include to do what you want.

Alex
 
Old 06-17-2003, 02:15 PM   #3
mrtwice
Member
 
Registered: Feb 2002
Distribution: xubuntu 8.10
Posts: 225

Original Poster
Rep: Reputation: 31
Thanks but I don't want to do that. This program will need to be very fast. I am sure there is something in native perl. Anyone else have a suggestion?
 
Old 06-19-2003, 03:03 PM   #4
llama_meme
Member
 
Registered: Nov 2001
Location: London, England
Distribution: Gentoo, FreeBSD
Posts: 590

Rep: Reputation: 30
It won't affect the speed of the program - compile it to bytecode and then run that.

Alex
 
Old 06-19-2003, 03:39 PM   #5
mrtwice
Member
 
Registered: Feb 2002
Distribution: xubuntu 8.10
Posts: 225

Original Poster
Rep: Reputation: 31
Thanks,

I ended up just making a module and using "use".
 
Old 06-19-2003, 03:42 PM   #6
llama_meme
Member
 
Registered: Nov 2001
Location: London, England
Distribution: Gentoo, FreeBSD
Posts: 590

Rep: Reputation: 30
Oh i see, lol, i should have read your post more carefully. I thought you explicitly didn't want to use modules, but that's not what you said, sorry...

Alex
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
include a file in perl script Ateo Programming 1 04-22-2005 10:53 PM
Include Custom Header Kenji Miyamoto Programming 3 01-13-2005 09:46 PM
header include path KDE4me Linux - Newbie 6 01-06-2005 07:17 AM
Problem with C++ include/header files! Pisces107 Programming 12 12-24-2003 12:06 AM
Clarifiacation on header file "/usr/include/a.out.h" swathisat Linux - Software 0 09-05-2003 01:12 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration