Re: config file modules confusion

2011-02-08 Thread Shlomi Fish
Hi Jim,

On Tuesday 08 Feb 2011 04:11:01 Jim Green wrote:
 Hello
 I searched cpan and was overwhelmed by the number of modules
 available.
 

Yes, there are many Config:: files around. A prominent Israeli Perl Monger has 
given an entertaining presentation on this subject in a Tel Aviv meeting 
comparing it to Alenby Street in Tel Aviv (the reference would be lost to non-
locals and was not obvious to us when we heard of it.). The slides are not 
online unfortunately.

 I want a config module that can do updates well, preserving formats of
 original file, preserving blank lines, comments, etc. which one should
 I use..?
 
 Config::General, Config::Simple, Config::Inifiles, just to name a
 few..
 

I believe (but am not entirely sure) that Config::IniFiles goes to great 
lengths to make sure comments and possibly also white space are preserved and 
can even be manipulated or changed. It should also preserve the order of the 
keys in the file, assuming there are no duplicate keys. 

I should note that I'm the current Config-Inifiles maintainer, and have done 
quite a lot of work on it recently, that involved modernising the test suite's 
code, applying patches, etc. The internals of Config-IniFiles are somewhat 
messy and suffer from some ancient Perl issues, and the test suite may not be 
comprehensive, but it should work fine for most people, and we'll handle any 
issue reported on the rt.cpan.org bug tracker given at least a reproducible 
test case.

Also see:

http://blogs.perl.org/users/steven_haryanto/2010/11/comparison-of-ini-format-
modules-on-cpan.html

(short URL - http://xrl.us/bihrdb ).

Of course, don't take my word for it, and write some test cases to see that 
everything works fine. This is assuming you won't find the INI-file format 
(which is limited to two levels) too restrictive.

Good luck!

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
My Favourite FOSS - http://www.shlomifish.org/open-source/favourite/

Chuck Norris can make the statement This statement is false a true one.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: config file modules confusion

2011-02-07 Thread terry peng



Mon, 7 Feb 2011 18:11:01 -0800 (PST) письмо от Jim Green 
student.northwest...@gmail.com:

 Hello
 I searched cpan and was overwhelmed by the number of modules
 available.
 
 I want a config module that can do updates well, preserving formats of
 original file, preserving blank lines, comments, etc. which one should
 I use..?
 
 Config::General, Config::Simple, Config::Inifiles, just to name a
 few..
 

I had used Config::Simple which I think is the right module for parsing a 
config file.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: config file modules confusion

2011-02-07 Thread Owen
On Mon, 7 Feb 2011 18:11:01 -0800 (PST)
Jim Green student.northwest...@gmail.com wrote:

 Hello
 I searched cpan and was overwhelmed by the number of modules
 available.
 
 I want a config module that can do updates well, preserving formats of
 original file, preserving blank lines, comments, etc. which one should
 I use..?
 
 Config::General, Config::Simple, Config::Inifiles, just to name a
 few..



I have used Config::General, its fine and easy to usse.



owen

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Config File Layout

2005-10-20 Thread Wiggins d'Anconia
Ryan Frantz wrote:
 Perlers,
 
  
 
 I'm working on a script that will need to email clients if it finds
 files in their respective outbound directories.  I've decided on a
 simple config file:
 
  
 
 [foo]
 
 [EMAIL PROTECTED]
 
  
 
 [bar]
 
 [EMAIL PROTECTED]
 
 [EMAIL PROTECTED]
 
  
 
  
 
 I've written a simple parser but it doesn't check for incorrect syntax.
 I looked at some of the Config:: modules and they appear to require
 Name=Value pairs.
 
  
 
 So my question is one of design; should I use the name=value pairing and
 one of the Config:: modules, or just leave it as is?  I'm going to be
 the only one maintaining the config file but, of course, I want the
 script and config file to be maintainable even if I'm not around.
 


One of the Config:: modules should handle your format above. You might
also consider AppConfig,

http://search.cpan.org/~abw/AppConfig-1.56/lib/AppConfig.pm

HTH,

http://danconia.org

 
 ry
 
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: Config file

2003-12-02 Thread Darbesio Eugenio

-Original Message-
From: Rod [mailto:[EMAIL PROTECTED]
Sent: martedì 2 dicembre 2003 16.55
To: beginners
Subject: Config file


What is the best way to read a config file for a perl script.  I have 
some very ugly code that can do it, but I would like to find something 
cleaner.

Thanks,
Rod.


## configuration file example clientMaster.ini
debug = 1
mailerFlag = 1 
mailServer = mailhost.drh.it
mailDir = hpi9670\\c\$\\inetpub\\mailroot\\pickup
mailDirTemp = D:\\VoxNauta\\temp  
t1 = 600
#t2 = 60
t2 = 0  
#tempiLog = cache 
logRun = cache

Try this simple code for reading the above configuration file:

open FILE_CONF,clientMaster.ini || die;
while (FILE_CONF) {
next if (/^#/ || /^;/ || /^$/ || /^\s/);
eval(\$$_);
}
close FILE_CONF;

# verifying variables read from configuration file
print debug = $debug\nt1 = $t1\nt2 = $t2\nmailServer = $mailServer\nmailDir = 
$mailDir\nmailDirTemp = $mailDirTemp\n;
print tempiLog = $tempiLog\nlogRun = $logRun\n;

E.


LOQUENDO S.p.A. 
Vocal Technology and Services 
www.loquendo.it 
[EMAIL PROTECTED]  
-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




CONFIDENTIALITY NOTICE
This message and its attachments are addressed solely to the persons
above and may contain confidential information. If you have received
the message in error, be informed that any use of the content hereof
is prohibited. Please return it immediately to the sender and delete
the message. Should you have any questions, please contact us by
replying to [EMAIL PROTECTED] Thank you


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Config file

2003-12-02 Thread Tom Kinzer
I've used Config::IniFiles before and it works very nice, especially nice if
you do a tie into a hash for all your values.

http://search.cpan.org/~wadg/Config-IniFiles-2.38/IniFiles.pm

-Tom Kinzer




-Original Message-
From: Rod [mailto:[EMAIL PROTECTED]
Sent: Tuesday, December 02, 2003 7:55 AM
To: beginners
Subject: Config file


What is the best way to read a config file for a perl script.  I have
some very ugly code that can do it, but I would like to find something
cleaner.

Thanks,
Rod.



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Config file

2003-12-02 Thread Bakken, Luke
 What is the best way to read a config file for a perl script.  I have 
 some very ugly code that can do it, but I would like to find 
 something 
 cleaner.

I've used Config::General for several production projects and it works
quite well.

Luke

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Config file

2003-12-02 Thread Dan Muey
 What is the best way to read a config file for a perl script.  I have 
 some very ugly code that can do it, but I would like to find 
 something 
 cleaner.

That depends very very much on the format of the config file.
You could use open() to read the file and parse it's contents 
into some kind of useable data structure (variables, array, hash,...) 

One of my favorite ways though is to put the goods I use in lots and 
lots of places into a module and import the goods I need:


use lib '/home/me/myperlmodules';
use MySuperProgramConfig; # has all the stuff I want in @EXPORT

Sorry I couldn't be more specific, I have no idea what your config 
file is like or what kind of info you're trying to get into the program
:)

Dmuey

 
 Thanks,
 Rod.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Config file

2003-12-02 Thread drieux
On Dec 2, 2003, at 7:55 AM, Rod wrote:

What is the best way to read a config file for a perl script.
I have some very ugly code that can do it, but I would like
to find something cleaner.
I like the Config::General module someone has recommended,
amongst the trade offs that one will have to resolve is how
much Stuff do you need, and how to access that stuff, and
how much 'generic parsing' as opposed to tailered parsing.
remember that 'art is in the eye of the beholder'.

My favorite way is in an OO'ish form where I start with
something on the order of
	my $web_config = new Dtk::...::ToolConf;

Then actually read them with

#
#
sub set_values
{
my ($me) = @_;

my $error = $me-webadmin_conf_file_name() unless $me-{file};
return $error if (ref($error) eq 'HASH');

open(FD, $me-{file}) or return({runtime_error =
unable to open config file $me-{file} : $!\n});
while(FD)
{
chomp;
s/#.*//;# strip comments
next if /^\s*$/;
if (/=/ ) {
s/\s+=/=/; # clean spaces before =
s/=\s+/=/; # clean spaces after =
s/\s+$//;  # clean trailing spaces
s/^\s+//;  # clean leading spaces
my ($k, $v) = split(/=/);
$me-{$k} = $v;
}   
}
close(FD);
$me-{values_set} = 1;

0;
} # end of set_values
And of course have a list of named accessors:

#
# The Accessors
#
sub config_sufix { $_[0]-{config_sufix} }
sub config_dir   { $_[0]-{config_dir} }
sub bin_dir  { $_[0]-{bin_dir} }
sub webmin_root  { $_[0]-{web_admin_root} }
sub webmin_port  { $_[0]-{web_admin_port} }
sub db_url   { $_[0]-{db_url} }
and some other junk that has to do with sanity checking,
and displaying them so that the config file can be
edited and updated, and yada-yada-yada.
{ yes, could have used AutoLoader - tried that,
it didn't take me where I wanted to go }
A part of the question you really want to ask
is how complex a config file do you want to begin
with, and can you live with the issues that come
from using a hash where the 'key/value' pairs are
accessed directly by the calling code.
Do you need to have complex configuration stuff,
if so why not lookt at the LibXml approach...
ciao
drieux
---

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Config file

2003-12-02 Thread Wiggins d Anconia


 
 On Dec 2, 2003, at 7:55 AM, Rod wrote:

 
 Do you need to have complex configuration stuff,
 if so why not lookt at the LibXml approach...
 

Particularly I suggest XML::Simple it allows you to both create your
config file and read in your config file using standard Perl data
constructs and is reasonably quick for smaller purposes.  I have also
had luck with AppConfig since it hasn't been mentioned yet, at least I
don't think. I have found XML the best bet for arbitrarily deep nested
config files though...

Whatever you decide, use a module!

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Config file

2003-12-02 Thread R. Joseph Newton
Rod wrote:

 What is the best way to read a config file for a perl script.  I have
 some very ugly code that can do it, but I would like to find something
 cleaner.

 Thanks,
 Rod.

It depends on how the config file is set up.  Asuming that your config
file is a simple name= value per line file, it is very simple:

my $options = {};

open IN, $option_file_name or die Could not open ini file: $!;
while (defined my $line = IN) {
   next unless $line;
   my ($key, $value) = split /\s*=\s*/, $line;
   $options-{$key} - $value;
}
close IN;

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: config file: a) what Module ? b) conditionals in config (for multiple hosts)

2003-10-31 Thread henq

Jenda Krynicky [EMAIL PROTECTED] schreef in bericht
news:[EMAIL PROTECTED]
 From: Wiggins d Anconia [EMAIL PROTECTED]

 To simplify this you may consider using two configs. One global
 that contains the settings that are the same everywhere (which will
 probably be most of them) and one local that will contain the
 specialties. And then read both the configs and merge them so that
 the local overwrites the global.



yes, that sunds like the rigtht solution. Funny, It was right under my nose
as this method is explained in the chapter of the Cookbook I mentioned...

like:  my %config = {%standard, %override};




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: config file: a) what Module ? b) conditionals in config (for multiple hosts)

2003-10-31 Thread henq

Wiggins D Anconia [EMAIL PROTECTED] schreef in bericht
news:[EMAIL PROTECTED]
  Hi,
 I have found in general the
 module that is chosen is based more on the format of the config file,


YAML is a rising star as formats go, I believe.




  where is hostname? is

it's a system command (back ticks).



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: config file: a) what Module ? b) conditionals in config (for multiple hosts)

2003-10-31 Thread Jenda Krynicky
From:  henq @onion.perl.org henq _ replace 0 by o [EMAIL PROTECTED]
 Jenda Krynicky [EMAIL PROTECTED] schreef in bericht
 news:[EMAIL PROTECTED]
  From: Wiggins d Anconia [EMAIL PROTECTED]
 
  To simplify this you may consider using two configs. One global
  that contains the settings that are the same everywhere (which will
  probably be most of them) and one local that will contain the
  specialties. And then read both the configs and merge them so that
  the local overwrites the global.
 
 yes, that sunds like the rigtht solution. Funny, It was right under my
 nose as this method is explained in the chapter of the Cookbook I
 mentioned...
 
 like:  my %config = {%standard, %override};

You want ( instead of { !

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: config file: a) what Module ? b) conditionals in config (for multiple hosts)

2003-10-31 Thread Wiggins d Anconia


 
 Wiggins D Anconia [EMAIL PROTECTED] schreef in bericht
 news:[EMAIL PROTECTED]
   Hi,
  I have found in general the
  module that is chosen is based more on the format of the config file,
 
 
 YAML is a rising star as formats go, I believe.
 
 
 
 
   where is hostname? is
 
 it's a system command (back ticks).
 

You missed the point, *I* know what 'hostname' is, but you restrict
yourself to platforms and environments that have it defined and open
yourself to security issues by attempting to use it in the manner you
stated.

On my RH 9.0 box hostname is in, /bin, on solaris 8 it is in /usr/bin,
other systems could put it in any of /usr/local/bin, /opt/bin,
/usr/sbin, /sbin, /my/really/long/weird/location/bin, etc., who knows if
windows even has 'hostname' and where it would be ok so you depend
on it being in the path, is the path setup correctly? what happens when
you put it in cron? how about under a chroot?  What happens when someone
throws, ~/bin in their path and wants to have a 'hostname' command that
logs into their NAT box and updates an IP address, ok they chose a dumb
name, but your script is now broke..  

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: config file: a) what Module ? b) conditionals in config (for multiple hosts)

2003-10-30 Thread Wiggins d Anconia


 Hi,
 
 a) I am looking for a module to handle config files. There are a number of
 these modules, like AppCconig.  Any consensus about The Right Module for
 this?
 

Whichever module gets the job done the way you want it.  I have used
AppConfig with some success but it fails to handle overly complex
structures (not its claim to fame either) some people (read: myself)
have come to expect in a config file so I switched to using XML::Simple
for more complex tasks.  Since I started out in the web world that
transition was obviously easy for me.  I have found in general the
module that is chosen is based more on the format of the config file,
which is usually left up to the person editing it and how comfortable
they are with doing so, or whether there will be an interface to editing
it. If the config file changes a lot and non-developers will edit it go
with something simple like AppConfig because it is relatively powerful
without complex layout restrictions, if the config file changes in
frequently, is updated by knowledgeable users, and/or has an interface
for making updates then go with a module that is easily written back out
 and allows for arbitrarily complex data structures

 
 b) As I develop one one machine and test/deploy on another, I want
 constructs in my config file like:
 
if (`hostname` eq 'dev_box') {
 mysql_dsn = 'foobar';
 } elsif ((`hostname` eq 'test_box'}
 mysql_dsn = 'abracadabra';
 ...
 
 Any support for that in your module of choice?
 
 I know of the use-just-perl-code approach (with 'do') in the Perl
Cookbook,
 but I am wondering if new insights exist.
 

Not that I know of, that is a rather complex deal, where is hostname? is
it in the path? what about machines that may not supply it?   If you
want a dev/q-a/prod set of config files i have found it more appropriate
to use the same structure in a set of 3 different config files, then
migrate the unique config files to each of the environments. Granted
when you change the structure you have to update 3 copies, but it
simplifies the programming, which *should* be the expensive part.

Just my $.02,

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: config file: a) what Module ? b) conditionals in config (for multiple hosts)

2003-10-30 Thread Jenda Krynicky
From: Wiggins d Anconia [EMAIL PROTECTED]
  b) As I develop one one machine and test/deploy on another, I want
  constructs in my config file like:
  
 if (`hostname` eq 'dev_box') {
  mysql_dsn = 'foobar';
  } elsif ((`hostname` eq 'test_box'}
  mysql_dsn = 'abracadabra';
  ...
  
  Any support for that in your module of choice?
  
  I know of the use-just-perl-code approach (with 'do') in the Perl
 Cookbook,
  but I am wondering if new insights exist.
  
 
 Not that I know of, that is a rather complex deal, where is hostname?
 is it in the path? what about machines that may not supply it?   If
 you want a dev/q-a/prod set of config files i have found it more
 appropriate to use the same structure in a set of 3 different config
 files, then migrate the unique config files to each of the
 environments. Granted when you change the structure you have to update
 3 copies, but it simplifies the programming, which *should* be the
 expensive part.

To simplify this you may consider using two configs. One global 
that contains the settings that are the same everywhere (which will 
probably be most of them) and one local that will contain the 
specialties. And then read both the configs and merge them so that 
the local overwrites the global. 

That was if you need to make the same change to all machines you can 
do it in the global config and then just copy the file.

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Config file regex...

2001-11-27 Thread Daniel Falkenberg

Hey all,

My sincerest apologize to all!  The last post has does exactly what I
want it to do.  There is no need have to do anything else at all with
the code.  Trial and error :)

Regards,

Dan

Hey all,

[Config File]
Linux Passwd File = /etc/passwd
New File= /home/test
Old File  = /home/test
Company Name  = Company Name
Company URL   = http://www.servername.com

Above is a config file I just created.  I want perl to be able to read
all the valus of this file into a hash.  Now I can do this no problem
with the following code...

$file = '/home/config';

sub read_config {
open FILE, $file or die cannot open '$file': $!\n;
  while( FILE ) {
$CONFIG_NAME = $1 and next if /^\s*\[\s*(.*?)\s*\]\s*$/;
next unless defined $CONFIG_NAME  /^\s*(.*?)\s*=\s*(.*?)\s*$/;
$CONFIG{$CONFIG_NAME}{$1} = $2;
  }
  close FILE;
  return %CONFIG;
}

As we all know :)  this will return the hash (%CONFIG) in the form of...

%CONFIG = (
 'Config File = {
'Linux Passwd File'   =
'/etc/passwd',
'New File'
= '/home/test',
'Old File'
= '/home/test',
'Company Name'
= 'Company Name',
'Company URL'
= 'http://www.servername.com'
},
   )

Now if the cofig file looked like this

[   Config File ]
Linux Passwd File = /etc/passwd
New File= /home/test
   Old File   = /home/test
Company Name  = Company Name
  Company URL   = http://www.servername.com

Then the scrip would still return the correct hash like so

%CONFIG = (
 'Config File = {
'Linux Passwd File'   =
'/etc/passwd',
'New File'
= '/home/test',
'Old File'
= '/home/test',
'Company Name'
= 'Company Name',
'Company URL'
= 'http://www.servername.com'
},
   )

. but what I need to know is if It is possible for the code above to
be manipulated in such a way where I or the user could write the config
file in the following way...


#This is the Config File Name
[Config File]
#This is the Linux password file
#Please make sure this is correct
Linux Passwd File = /etc/passwd

New File= /home/test
Old File  = /home/test
   Company Name  = Company Name
Company URL   = http://www.servername.com

So in other words I still want to be able to exactly what I can do now
but also place a # (comment) any where in the script and then have the
code completly ignore it.  I also wna tto be able to place a new line or
2 or 3 in the code and have the code completly ignore it.

Is this possible?

Kind regards,

Dan

==
VINTEK CONSULTING PTY LTD
(ACN 088 825 209)
Email:  [EMAIL PROTECTED]
WWW:http://www.vintek.net
Tel:(08) 8523 5035
Fax:(08) 8523 2104
Snail:  P.O. Box 312
Gawler   SA   5118
==


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Config file regex...

2001-11-27 Thread Hasanuddin Tamir

On Wed, 28 Nov 2001, Daniel Falkenberg [EMAIL PROTECTED] wrote,

 Hey all,
 
 [Config File]
 Linux Passwd File = /etc/passwd
 New File  = /home/test
 Old File= /home/test
 Company Name  = Company Name
 Company URL   = http://www.servername.com
 
 Above is a config file I just created.  I want perl to be able to read
 all the valus of this file into a hash.  Now I can do this no problem
 with the following code...

Do you want just to have your config file parsed, or do you want to learn
about regex for parsing config file.

If you want the former, there's a plenty of modules at CPAN that do just
that.  If you want the latter, well get one of those modules you like and
study the code.


san
-- 
Trabas - http://www.trabas.com



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]