On Dec 11, 2003, at 12:16 PM, Eric Walker wrote:


Ok,, back to some laymen terms hehe...

not sure I can do that, but hey, I'll try anything once...


it seems that the two issues are

        a. Parser Mechanics
        b. File Format.

The file is read by an application and what I am doing is this.
The application use to read this file that was created by hand
to set some internal settings.

The first question is who wrote the application, and, well, to be polite, did the application writer share the parser code the it is using to read the file. But we will get back to this...

for the sake of argument let's assume the simpler

myApp -f config_file

and myApp parses the config_file and set's it's internal values.
{ yes, the myApp could be reading some 'default config file',
'user preferance files', what ever - there exists some file
let us call it the 'config_file' that will be read to configure
the application . }

[..]
I am trying to dump the current values from the program
and do a compare between the file I auto created
and whats in the program now.

There exists some 'signal' or 'messaging' method that will tell myapp:

woof your current configuration data into a file

{ woof - technical term denoting, to heave up the foo.. }

[..]
So the keys Idea is a no go. I am glad at least the data was good enough for us
to kick around. The way they are writting is the only way they can be
do to the application that reads them.

Actually what you will want to step into is the notion of 'subs' - cf perldoc perlsub, and you can 'abstract' the 'grovel_woof_file()' so that it will return you a hash.

eg:

        suf grovel_woof_file
        {
                my ($filename) = @_;
                # return undefined if we can not read the file.
                return undef unless (-r $filename );
                # steal from dzhuo[at]looksmart.net (David)
                open(FD, $filename) or die "unable to open $filename :$!";
                my $parens;
                $parens .= $_ while(<FD>); # read in the file
                close(FD);
                # cf perdoc map - and thank david.
                my %hash = map split, $parens =~ /\(+([^()]+)\)+/g;

                \%hash; # return hash ref
        }

{ Yes, I know, that will ultimately need to be grown out
a bit to deal with the 'variations' in the 'configuration file'
as noted previously... }

then you could do say

        my $def_hash = grovel_woof_file($default_file);
        make_myApp_woof($new_file); # function to make running myApp Woof...
        my $new_hash = grovel_woof_file($new_file);

        foreach my $key ( keys %$def_hash )
        {
                if ( exists($new_hash->{$key}))
                {
                        if ( $new_hash->{$key} eq $def_hash->{$key}) {
                                print "have same key $key\n";
                        } else {
                                whine("new key value", $key, $new_hash->{$key});
                        }
                } else {
                        whine("no key value", $key, $def_hash->{$key});
                }
        }

we leave the whine() function to you as an exercise to whine about.
{ we will serve no whine() before it's time... }

How do you determine if an application has a portable library?

well it is less about being 'portable' in terms of being able to run on more than one os - as much as it is about exposing the parser complex that the application is using.

WARNING: drieuxishSoapBoxMoment

<drieuxishSoapBoxMoment>
        Files do not Just GROW in File Systems! There
        exists some 'code foo' that creates it, normally
        because there is some 'parser foo' that will read it
        into applications to set configuration information.

        Writers of Configuration File Parsers SHOULD be polite
        and offer up access to their Configuration File Parsing
        routines so that they can be exposed in other languages,
        such as Perl, so that the support crew can be more effective!

        App Writers who create WACKO configuration file stuff so as
        to create Wacko Configuration File Parsers that they are not
        willing to share with their support crew are building up bad
        kharma, and the BadKharmaFerrie Will Get them at PayBack!
</drieuxishSoapBoxMoment>

{ I feel better now. }

I know nothing of that but sounds like something neat and witty..
If I could do that and use a perl module
that would be nice.

what you will want to learn down that path is


        perldoc h2xs
        perldoc perlmodlib

and specifically you will want to pick up
learning Perl Objects, References and Modules,
as well as the 3rd Edition of Programming perl...

perlknucklehead


I know nothing of xml I am sorry to say. you kinda dove off of the big diving board and I am still back putting on my floaters. hehehe...

sorry, that Must have been my evil twin Skippy....


ciao
drieux



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




Reply via email to