Re: which module to read configuration file?
Richard Bailey r...@rtbaileyphd.com writes: There is code available from my wizard at http://www.rtbaileyphd.com/perlwizard that is doing something fairly similar to what you described. Use PerlWizard to generate a simple test program, run it once, and then examine the contents of the pwiz subirectory, which is where the config files go. These are used in conjunction with Getopt::Long as well. Thank you very much for you input! I looked at the web page, and it seems that the perlwizard is written in java, which is something I stay away from as much as possible ... I ended up with a pretty simple config file like this: sender : subject : action1, action2, ..., actionN From there, I've turned it into an emacs org-mode table for easier editing. The script needs less than 100 lines to read it, including all checks. I really like those tables :) -- Knowledge is volatile and fluid. Software is power. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
which module to read configuration file?
Hi, is there a module available to read configuration files which are like this: arbitrary_denominator-00 | alternate-denominator-00 | alternate-denominator-01 [| ...] { itemA = some string itemB = some integer itemC = some float itemD = some CSV } as in: postmas...@example.com | u...@example.com { itemB = 5 itemC = 3.2 itemD = foo, bar, example } The arbitrary_denominator would allow to retrieve the configuration options given for that particular thing (in this case an email address). It doesn't /have/ to be exactly like this; I simply used a way of writing it which I'd find pretty. I merely want to kinda have a unique handle of a set of options that apply so that I can access those in my script, like: my $foo = '.*@example.com'; my $config = getconfig-new(some.file); foreach my $denom (@config-denominators) { if($denom =~ m/$foo/) { my $thisitem = config-itemC[$_]; print itemC of $denom: $thisitem\n if defined($thisitem); } } I hope you get the idea ... I'm thinking something like Getopt::Long, but for configuration files like above instead of commandline options. I don't want to use something like a CSV file for this because each entry must not be required to have every possible item defined, and a CSV file would be rather difficult to maintain. It would be possible, though inconvenient, to use a single file for each denominator. I think that at the minimum, one file per /array of denominators/ might do. However, with multiple files, all of them would have to be examined every time a config item for a denominator is requested, which could lead to somewhat poor performance, hence I'd rather use a single file. This would be one step along the way of solving the problem of printing (pre-filtered) incoming email, including the attachments, by various criteria (when xx sends a PDF then print it unless it has more than N pages and print all HTML from xx, but print all PDF from xx when the subject is foo; never print the PDF sent by zz and only the first page of HTML from zz ...): I should need a configuration file which is easy to edit, for specifying such criteria in sufficient detail. Then a perl script will use various tools to do the decoding and printing, considering the config. I'm expecting it to start somewhat simple and getting more complicated over time when users figure out that they will need a lot of criteria to keep the amount of paper wasted within reasonable limits, so the config file format must be easily extendable with further options. Your ideas will be appreciated. -- Knowledge is volatile and fluid. Software is power. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: which module to read configuration file?
lee l...@yun.yagibdah.de writes: Hi, is there a module available to read configuration files which are like this: arbitrary_denominator-00 | alternate-denominator-00 | alternate-denominator-01 [| ...] { itemA = some string itemB = some integer itemC = some float itemD = some CSV } Following-up my own question: I found [1] which appears to come close to what I'm looking for. Of course, I'd still love to hear your ideas :) [1]: https://metacpan.org/pod/Config::JSON -- Knowledge is volatile and fluid. Software is power. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: which module to read configuration file?
There is code available from my wizard at http://www.rtbaileyphd.com/perlwizard that is doing something fairly similar to what you described. Use PerlWizard to generate a simple test program, run it once, and then examine the contents of the pwiz subirectory, which is where the config files go. These are used in conjunction with Getopt::Long as well. Best Regards, R. T. Bailey -Original Message- From: lee [mailto:l...@yun.yagibdah.de] Sent: Saturday, August 30, 2014 12:09 PM To: beginners@perl.org Subject: Re: which module to read configuration file? lee mailto:l...@yun.yagibdah.de l...@yun.yagibdah.de writes: Hi, is there a module available to read configuration files which are like this: arbitrary_denominator-00 | alternate-denominator-00 | alternate-denominator-01 [| ...] { itemA = some string itemB = some integer itemC = some float itemD = some CSV } Following-up my own question: I found [1] which appears to come close to what I'm looking for. Of course, I'd still love to hear your ideas :) [1]: https://metacpan.org/pod/Config::JSON https://metacpan.org/pod/Config::JSON -- Knowledge is volatile and fluid. Software is power. -- To unsubscribe, e-mail: mailto:beginners-unsubscr...@perl.org beginners-unsubscr...@perl.org For additional commands, e-mail: mailto:beginners-h...@perl.org beginners-h...@perl.org http://learn.perl.org/ http://learn.perl.org/
How to use a configuration file?
Moin, I wrote a simple http proxy. This script have some configuration entries like my $remoteProxy = 'http://localhost:8080/'; $ENV{'http_proxy'} = $remoteProxy; . . # initialisation my $proxy = HTTP::Proxy-new( port = 3128 ); $proxy - host(127.0.0.1); I want to get some of these values (remoteProxy, the port and the IP address and some things more) from a configuration file. What is a good way to do this? What is a good format for this file? Human readable and easy to parse? Thanks -- |Michael Renner E-mail: michael.ren...@gmx.de | |D-81541 Munich GermanyICQ: #112280325 | |Germany Don't drink as root! ESC:wq -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: How to use a configuration file?
On Sat, Mar 14, 2009 at 08:41, Michael Renner michael.ren...@gmx.de wrote: Moin, snip I want to get some of these values (remoteProxy, the port and the IP address and some things more) from a configuration file. What is a good way to do this? What is a good format for this file? Human readable and easy to parse? snip I like YAML*, it is human readable, cross language, and can handle almost any data structure you need to store. I use YAML::Syck** in Perl to read it. * http://en.wikipedia.org/wiki/Yaml ** http://search.cpan.org/dist/YAML-Syck/lib/YAML/Syck.pm -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: How to use a configuration file?
From: Chas. Owens chas.ow...@gmail.com I want to get some of these values (remoteProxy, the port and the IP address and some things more) from a configuration file. What is a good way to do this? What is a good format for this file? Human readable and easy to parse? snip I like YAML*, it is human readable, cross language, and can handle almost any data structure you need to store. I use YAML::Syck** in Perl to read it. Like the Captchas that offer just images, YAML is human readable just for the humans that can see. It is very hard to read by the blind though. It is also hard to use it in POD documentations because the POD indents the text and in some cases in HTML pages also. Config::Any module allows using more configuration formats, including the pretty well known Apache style configuration (which is offered by Config::General module). Octavian -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
create a tree of a configuration file content
Hello, I would like to parse ms .adm files. This files have a tree structure that look like Category Name1 category Name2 categor Name3 Policy pol1 data lines here ... End policy Policy pol2 data lines here ... End policy end category category Name4 . Is there a easy way to load this files as create a tree of the content of this type of file ? I need it to extract single policies including the category names they are embedded in. The content of the single policies can be one object and must not be split. Thanks Andreas -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: create a tree of a configuration file content
On Mon, Dec 1, 2008 at 5:01 PM, Andreas Moroder [EMAIL PROTECTED] wrote: Hello, I would like to parse ms .adm files. This files have a tree structure that look like Category Name1 category Name2 categor Name3 Policy pol1 data lines here ... End policy Policy pol2 data lines here ... End policy end category category Name4 . Is there a easy way to load this files as create a tree of the content of this type of file ? I need it to extract single policies including the category names they are embedded in. The content of the single policies can be one object and must not be split. Thanks Andreas -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ Hi Andreas, A quick google search got me this link: http://www.novell.com/coolsolutions/trench/3253.html I have no idea how good it is but somehow I expect novell to be resonably good at workign these kinds fo things out. As far as I can tell it is released under some form of open source license or the other so it might be exactly what you are looking for. Regards, Rob
Re: Configuration File generator
On 4/24/05, Tommy Nordgren wrote: I wan't links to any useful tools for generating configure scripts in perl. That is, tools to automatically generate the configure script for open-source C/C++ projects. Perl itself uses a Configure script generated using the metaconfig tool, which is (as best asI could find) poorly documented. See (if you must): http://search.cpan.org/dist/Config-Maker/ The Configure script itself can be seen here: http://search.cpan.org/src/NWCLARK/perl-5.8.6/Configure IMHO, for C and C++ projects, you are better off using the Automake and Autoconf tools from the GNU Foundation: http://www.gnu.org/software/automake/ http://www.gnu.org/software/autoconf/ Automake itself is written in Perl. HTH, -- Offer Kaye -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Configuration File generator
I wan't links to any useful tools for generating configure scripts in perl. That is, tools to automatically generate the configure script for open-source C/C++ projects. Home is not where you are born, but where your heart finds peace - Tommy Nordgren, The dying old crone -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Configuration File
Hi Perlers, I'm trying to implement one of the recipes I found in the Perl Cookbook. It is 8.16. Reading Configuration Files recipe. Here are some snippets from that text: ... Or better yet, treat the config file as full Perl code: do $ENV{HOME}/.progrc; ... The second solution uses do to pull in raw Perl code directly. When used with an expression instead of a block, do interprets the expression as a filename. This is nearly identical to using require, but without risk of taking a fatal exception. ... You might wonder what context those files will be executed under. They will be in the same package that do itself was compiled into. Typically you'll direct users to set particular variables, which, being unqualified globals, will end up in the current package. If you'd prefer unqualified variables go into a particular package, do this: { package Settings; do $ENV{HOME}/.myprogrc } As with a file read in using require or use, those read in using do count as a separate and unrelated lexical scope. That means the configuration file can't access its caller's lexical (my) variables, nor can the caller find any such variables that might have been set in the file. It also means that the user's code isn't held accountable to a pragma like use strict or use integer that may be in effect in the caller. My code looks like this (for testing): #!/usr/bin/perl # configtest.pl use warnings; use strict; { package Config; do configtest.conf } print $_\n for( @Config::FILE_NAME ); My configtest.conf file looks like this: # A list of file names @FILE_NAME = qw[ /This/is/a/test /This/is/also/a/test /And/this/is/the/last/test ]; Now, this code runs, and produces the expected output. However, it also gives me a warning: Name Config::FILE_NAME used only once: possible typo at ./configtest.pl line 7. I realize I can just turn my pragmas off after testing/implementation to get rid of this, but is there a better way? Perhaps my Perl Cookbook is just old (yup, 1st edition. Has this recipe been updated?) --Errin -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Configuration File
Errin Larsen wrote: { package Config; do configtest.conf } print $_\n for( @Config::FILE_NAME ); snip Now, this code runs, and produces the expected output. However, it also gives me a warning: Name Config::FILE_NAME used only once: possible typo at ./configtest.pl line 7. I realize I can just turn my pragmas off after testing/implementation to get rid of this, but is there a better way? Nothing prevents you from declaring @FILE_NAME: package Config; our @FILE_NAME; do configtest.conf; print $_\n for @FILE_NAME; -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Configuration File
On Thu, 30 Sep 2004 23:30:16 +0200, Gunnar Hjalmarsson [EMAIL PROTECTED] wrote: Nothing prevents you from declaring @FILE_NAME: package Config; our @FILE_NAME; do configtest.conf; print $_\n for @FILE_NAME; -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl doesn't that kinda defeat the purpose of declaring the Config name space? I was trying to keep the variables in the configtest.conf file in a different name space than the main program. I don't HAVE to do this, just thought it seemed like a good way to keep the two, potentially conflicted, name spaces apart. I wanted to see the variables created in the Config name space require a dereference (is that the right word?), ala Config::FILE_NAME. That way, if the main code ALSO has a FILE_NAME variable, the contents of the (at run time, unknown to the main developer) config file. I hope that's making sense. --Errin -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Configuration File
Errin Larsen wrote: Gunnar Hjalmarsson wrote: Nothing prevents you from declaring @FILE_NAME: package Config; our @FILE_NAME; do configtest.conf; print $_\n for @FILE_NAME; doesn't that kinda defeat the purpose of declaring the Config name space? Can't see how. It is being declared within package Config. I was trying to keep the variables in the configtest.conf file in a different name space than the main program. That sounds wise, and I didn't suggest anything else. I wanted to see the variables created in the Config name space require a dereference (is that the right word?), No. You mean require the fully qualified names. ala Config::FILE_NAME. If you don't export anything from package Config, you still need to use the fully qualified names when calling those variables from other packages, so I don't think that's a reason either to not declare the variables in package Config. -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Using strict and a configuration file?
just define all vars in ur conf file with a scope reslution eg $global::test = 'hello'; Octavian Rasnita wrote: Hi all, Is it possible to use use strict; if I get the variables from a configuration file? I've tried: use strict; require f:/xxx/config.txt; #In the configuration file I have a line like my $test = test test test; print Content-type: text/html\n\n; print $test; This gives me an error that I should define the variable $test. I don't want to define it in the script but in the configuration file. However, if I define it in the script with my $test; the script prints an empty string and doesn't take the variable from the configuration file. Is it possible to use strict, or it is necessary to use no strict;? Another problem, maybe bigger is that even though the script is running fine, it give me errors in the log file telling me that the variable $xxx and $yyy, ... is used only once. Is there a good method to define variables for more scripts in a single configuration file? I don't want to store my email address and other settings in each script because I may change that address, and then I will need to modify a lot. Thank you. or I have another solution for defining all the variables in a configuration file? Teddy, [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Using strict and a configuration file?
Teddy -- ...and then Octavian Rasnita said... % % Hi all, Hello! % % Is it possible to use use strict; if I get the variables from a % configuration file? % % I've tried: % % use strict; % require f:/xxx/config.txt; Have you tried use f:/xxx/config.txt; instead? From my reading of the camel book, require happens at run time and thus anything it defines won't be defined at compile time and strict will puke, whereas use essentially performs a require at compile time and then lets yuou import declarations into your own namespace, the latter part of which may also be useful (no put intended ;-) in light of some of the scoping concerns brought up in other replies. HTH HAND :-D -- David T-G * It's easier to fight for one's principles (play) [EMAIL PROTECTED] * than to live up to them. -- fortune cookie (work) [EMAIL PROTECTED] http://www.justpickone.org/davidtg/Shpx gur Pbzzhavpngvbaf Qrprapl Npg! msg05345/pgp0.pgp Description: PGP signature
RE: Using strict and a configuration file?
I had this same question answered on the perl beginners list. Object oriented programming was recommended. Someday I want to learn about that But for now what I did was give the configuration file and the scripts that use it the same package name and then I defined these variables as global Variables with the use vars. It works ok with the use strict, but it may Violate some standard perl coding practices against global variables. Maureen -Original Message- From: Octavian Rasnita [mailto:[EMAIL PROTECTED]] Sent: Friday, June 07, 2002 12:12 AM To: [EMAIL PROTECTED] Subject: Using strict and a configuration file? Hi all, Is it possible to use use strict; if I get the variables from a configuration file? I've tried: use strict; require f:/xxx/config.txt; #In the configuration file I have a line like my $test = test test test; print Content-type: text/html\n\n; print $test; This gives me an error that I should define the variable $test. I don't want to define it in the script but in the configuration file. However, if I define it in the script with my $test; the script prints an empty string and doesn't take the variable from the configuration file. Is it possible to use strict, or it is necessary to use no strict;? Another problem, maybe bigger is that even though the script is running fine, it give me errors in the log file telling me that the variable $xxx and $yyy, ... is used only once. Is there a good method to define variables for more scripts in a single configuration file? I don't want to store my email address and other settings in each script because I may change that address, and then I will need to modify a lot. Thank you. . or I have another solution for defining all the variables in a configuration file? Teddy, [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Using strict and a configuration file?
Hi all, Is it possible to use use strict; if I get the variables from a configuration file? I've tried: use strict; require f:/xxx/config.txt; #In the configuration file I have a line like my $test = test test test; print Content-type: text/html\n\n; print $test; This gives me an error that I should define the variable $test. I don't want to define it in the script but in the configuration file. However, if I define it in the script with my $test; the script prints an empty string and doesn't take the variable from the configuration file. Is it possible to use strict, or it is necessary to use no strict;? Another problem, maybe bigger is that even though the script is running fine, it give me errors in the log file telling me that the variable $xxx and $yyy, ... is used only once. Is there a good method to define variables for more scripts in a single configuration file? I don't want to store my email address and other settings in each script because I may change that address, and then I will need to modify a lot. Thank you. or I have another solution for defining all the variables in a configuration file? Teddy, [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Getting content of a configuration file
Sven [EMAIL PROTECTED] wrote in message 027901c204e8$fa475da0$14e307d5@brian">news:027901c204e8$fa475da0$14e307d5@brian... ... $context = $q-param(context); require conf.txt; open(READ, conf.txt) or die Error opening file: conf.txt, Errorcode: $!\n; close(READ); I dont understand the open then close. The require is all thats necessary. if ($context eq assembly) { %conf_data = %assembly ; } elsif ($context eq basic) { %conf_data = %basic ; } Instead of doing this, use symbollic references. %conf_data = %{$context}; and you are all set. You will have to turn off strict refs for this line of code when use strict; is in effect. Todd W. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Getting content of a configuration file
Hi Teddy, you may try the following: Write into your conf-file: %assembly = ( title= 'Assembly language page', description = 'Download free manuals and tutorials for assembly language', . ); %basic = ( title= 'Basic and Visual Basic page', description = 'Download Basic and Visual Basic tutorials', . ); And in your main-skript which should be called with something like context=basic or assembly or ... as a parameter: use CGI; $q = new CGI; $context = $q-param(context); require conf.txt; open(READ, conf.txt) or die Error opening file: conf.txt, Errorcode: $!\n; close(READ); if ($context eq assembly) { %conf_data = %assembly ; } elsif ($context eq basic) { %conf_data = %basic ; } print $q-header; print END_OF_HTML; HTML HEAD TITLE$conf_data{title}/TITLE META HTTP-EQUIV=Expires CONTENT=0 /HEAD BODY H1$conf_data{description}/H1 /BODY /HTML END_OF_HTML - Original Message - From: Octavian Rasnita [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, May 25, 2002 4:06 PM Subject: Getting content of a configuration file Hi all, I want to use a configuration file for a script and maybe I look in the wrong direction. Please tell me if I have a better solution. I want to make a script that generates HTML pages. I already have the script but I need to manually enter the page title, the keywords, the description, a page header and a footer manually. I want to get these strings from a configuration file. In this configuration file I want to have the strings for all web pages. In the configuration file I am thinking to have something like: page=assembly title=Assembly language page keywords=assembly language code asm description=Download free manuals and tutorials for assembly language header=This is the header text footer=This is the footer text page=basic title=Basic and Visual Basic page keywords=visual basic vb script ActiveX description=Download Basic and Visual Basic tutorials header=This is the page header footer=This is the page footer Finally I would like to have something like: %assembly=(title='...', keywords= '...', description= '...', header= '...', footer='...'); %basic=(title='...', keywords= '...', description= '...', header= '...', footer='...'); However, I don't know if it is possible to generate variables like %assembly on the fly (because in that configuration file I will add variables for more pages. But maybe I am looking in a wrong direction and I can have another solution. I thought I could put in the configuration file something like: assembly.title=Assembly language page assembly.keywords= assembly.description=... then to split the part before the = sign where is the . Please tell me if you have a better idea for such a configuration file I want. Thank you. Teddy, [EMAIL PROTECTED] -- 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]
Getting content of a configuration file
Hi all, I want to use a configuration file for a script and maybe I look in the wrong direction. Please tell me if I have a better solution. I want to make a script that generates HTML pages. I already have the script but I need to manually enter the page title, the keywords, the description, a page header and a footer manually. I want to get these strings from a configuration file. In this configuration file I want to have the strings for all web pages. In the configuration file I am thinking to have something like: page=assembly title=Assembly language page keywords=assembly language code asm description=Download free manuals and tutorials for assembly language header=This is the header text footer=This is the footer text page=basic title=Basic and Visual Basic page keywords=visual basic vb script ActiveX description=Download Basic and Visual Basic tutorials header=This is the page header footer=This is the page footer Finally I would like to have something like: %assembly=(title='...', keywords= '...', description= '...', header= '...', footer='...'); %basic=(title='...', keywords= '...', description= '...', header= '...', footer='...'); However, I don't know if it is possible to generate variables like %assembly on the fly (because in that configuration file I will add variables for more pages. But maybe I am looking in a wrong direction and I can have another solution. I thought I could put in the configuration file something like: assembly.title=Assembly language page assembly.keywords= assembly.description=... then to split the part before the = sign where is the . Please tell me if you have a better idea for such a configuration file I want. Thank you. Teddy, [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]