Schrift
Wiki:Tipp zum Debugging: use Data::Dumper; local $Data::Dumper::Useqq = 1; print Dumper \@var;
[thread]6712[/thread]

Programm-Konfiguration: ueber AppConfig && Cmdline Options



<< >> 1 Eintrag, 1 Seite
coax
 2005-02-16 19:06
#51803 #51803
User since
2003-08-11
457 Artikel
BenutzerIn
[default_avatar]
Ich hab mein Programm durch AppConfig und einer conf-File mit etwas mehr Komfort ausgestattet.
Der "AppConfig + .conf-File"-Part funktioniert auch wunderbar, die Probleme hab ich mit den CmdlineOptions,
die Argumente der Art ARGCOUNT_HASH funktionieren irgendwie nicht so wie sie sollen.

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/perl

 use strict;
 use warnings;

 use AppConfig;

 my $config = new AppConfig;

 $config->define("module|modules|m=s%" => { DEFAULT => 'off' });

 $config->file(\*DATA) if @ARGV == 0;

 $config->getopt('gnu_getopt');

 my %modules = %{ $config->modules()};

 print "# $_ = $modules{$_}\n" for keys %modules;

 printf("Module: %s = %s\n", $_, $modules{$_})
     for grep { defined $modules{$_} && lc $modules{$_} eq 'on' }
              keys %modules;

_ _DATA_ _
# Configuration File

Module FTP = On
Module WWW = Off

Ohne Argumente soll der Programmlauf allein ueber die Konfigurationsdatei bestimmt werden.

Code: (dl )
1
2
3
4
# Ausgabe (ohne Argumente):
# FTP = On
# WWW = Off
Module: FTP = On


Rufe ich es jetzt aber wie folgt auf
Code: (dl )
% myapp --module 'WWW=On'

existiert dann zwar der Schluessel WWW im Modules-Hash ($config->modules()) aber ist auf undef gesetzt, statt auf on.

Code: (dl )
1
2
3
# Ausgabe:
Use of uninitialized value in concatenation (.) or string at myapp line 18.
# WWW =


Any ideas ?

Schon mal vielen Dank!

Grusz Christian.
,,Das perlt aber heute wieder...'' -- Dittsche
<< >> 1 Eintrag, 1 Seite



View all threads created 2005-02-16 19:06.