Leser: 1
8 Einträge, 1 Seite |
QuoteAs 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.
QuoteWe've never actually seen anyone (except Larry) use that approach in production code.
1
2
3
4
5
6
7
8
9
10
while (<CONF>)
{
chomp;
s/#.*//; #kein newline
s/^\s+//; #keine kommentare
s/\s+$//; #keine führenden whitespaces
next unless length;
my ($var, $value) = split(/\s*=\s*/,$_,2);
$config{$var} = $value;
}
1
2
3
4
5
6
7
8
$name = replace($cfg{NAME}, {NAME => "jochen"});
print "hallo $name\n";
sub replace {
my ($data, $fill) = @_;
$data =~ s{%%(.*?)%%}{exists($fill->{$1}) ? $fill->{$1} : ""}gse;
return $txt;
}
use vars qw( $foo @bar );
8 Einträge, 1 Seite |