develooper Front page | perl.beginners | Postings from February 2002

Re: Include file

Thread Previous
jeff loetel
February 1, 2002 10:58
Re: Include file
Message ID:
You could use the module that I am trying to use but having problems:

or you could use this (it works but is to limited for what I need):


my $file = "/dir/somefile.txt";
open (CONFIG, "< $file") or die "Can't open $file";
while (<CONFIG>) {
       chomp;                  #no newline
       s/#.*//;                #no comments
       s/^\s+//;               #no leading white
       s/\s+$//;               #no trailing white
       next unless length;     #anything left?
       my ($var, $value) = split(/\s*=\s*/, $_, 2);
       $config{$var} = $value;

#then print everything or a specific $var 

That should do the trick for you, if you have any luck see my positing
on AppConfig. AppConfig is used to do the same thing plus it has a lot
more features in it, I just can't get the damn thing to work. If this
works for you and you have a spare minute I would appreciate any help
that I could get on the AppConfig (two brains are better than one). If
you don't have time, don't worry about it.


On Fri, 2002-02-01 at 09:13, gross, cedric wrote:
> I have a set of program to do which is using always same var.
> So I would like to defined a small file where I defined my var (like
> $database="toto" $host="localhost" etc..) and then include it in my
> other program, but
> How to do that ?
> I try "use" but it's seems that is for complete module.
> "require" seems to be for version behavior
> and include seems not be supported...
> I browse doc but I found nothing..

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About