perl处置properties文件

perl处理properties文件

使用Config::Properties模块,详情请见:http://search.cpan.org/~salva/Config-Properties-1.70/Properties.pm

 

use Cwd;
BEGIN {
	$ipath = getcwd . "/lib/perl/pm/";
	push @INC, $ipath;
}
use Config::Properties;

my $properties = new Config::Properties();

open PROPS, "< $propfile"
	or die "unable to open properties file";
	
$properties->load(*PROPS);
$value = $properties->getProperty( $key );

# saving...
open PROPS, "> $propfile"
	or die "unable to open properties file for writing";

$properties->setProperty( $key, $val );

$properties->format( '%s=%s' );
$properties->store(*PROPS, $header );

close PROPS;