From: "John W. Krahn" <[EMAIL PROTECTED]>Jon Mathews wrote:
Not sure how else to word this. Basically, I have a util which reads a config file
That is one "wheel" that has been invented many times before:
http://search.cpan.org/author/MWS/CONFIG-V0.99.11/Hash.pm http://search.cpan.org/author/AVAJADI/Config-Abstract-0.12/Abstract.pm http://search.cpan.org/author/KANE/Config-Auto-0.11/lib/Config/Auto.pm http://search.cpan.org/author/JONBJ/Config-Easy-0.2/lib/Config/Easy.pm
[snip]
etc. etc...
Thanks - some of these are close to drop-in solutions which I will consider in the future where applicable (like code that I actually run). However, they add complexity to the config file which will be created/maintained by lots of rather low-level users. I would rather they not have to know names of variables, keys, formats, etc. any more than absolutely necessary. They seem to like the last working method okay - and it is working out better than I expected.
Since I actually need to read multiple hashes from the config file, I saw no example which was an amalgam of having the minimal amount of the structure in the config file and the rest in the code - to keep the config file simple.
The main problem is that "low-level users" are not Perl programmers but your config file format relies on a Perl friendly syntax instead of a more user friendly syntax. What happens if your users put commas or parentheses in the data?
to set metadata which is kept finally in a HOH. I want to support another form of the config file, though, which may be less flexible, but is easier to read. Here is some example code which shows my progression of thinking in 4 sections - the last of which is the one that shows what I want to do:
#!/usr/bin/perl -w use strict ; { # Out of the book method. my %Hash = () ; print "Using values\n" ; %Hash = ( FileName => '^.ssh$', IsDir => 1, Desc => "Secure Shell directory" ) ; foreach ( keys %Hash ) { print "Key = $_\n" ; print "\$Hash{$_}=" . $Hash{$_} . "\n" ; } ; }
Just curious, which book did you get this method from?
Advanced Perl Programming - O'Reilly - first edition - p. 10.
Page 10 is the section on "References to Anonymous Storage" but there is no anonymous storage in your example?
The reasons I asked is because one would normally combine the declaration and assignment for the hash in one statement and you are using interpolation for the $_ scalar but not for the $Hash{$_} scalar.
{ # Out of the book method. print "Using values\n" ; my %Hash = ( FileName => '^.ssh$', IsDir => 1, Desc => "Secure Shell directory" ) ; foreach ( keys %Hash ) { print "Key = $_\n" ; print "\$Hash{$_}=$Hash{$_}\n" ; } }
John -- use Perl; program fulfillment
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>