ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 使用了一下perl的XML::Smart模块,真是太好用了

使用了一下perl的XML::Smart模块,真是太好用了

原创 Linux操作系统 作者:bulletming 时间:2019-06-20 10:54:05 0 删除 编辑

现在只是那它来做一下config file,不过这个对于数据交互,数据存储都是非常非常有用啊!xml文件进了perl里边就可以像hash一样随便用了


下边这段代码是初始化一个xml文件的

[root@dw01 robin]# more txml.pl
#! /usr/bin/perl
use strict;
use warnings;
use XML::Smart;
use DBI;

my $conn_str = 'DBI:Oracle:host=dw01-vip;sid=IEODDW1';
my $user = 'dw';
my $password = '******';

my $dbh;

login();

my $sql_statement = qq{
select table_name
from user_tables
order by table_name
};
my $parts_ref = $dbh->selectall_arrayref( $sql_statement );

logoff();

my $xml = XML::Smart->new('./tables.xml');

my $table;
foreach (@$parts_ref) {
$table = {
name => $_->[0],
force_save_days => 61,
ignore_trun_days => [qw(1 15)]
};
push(@{$xml->{tables}->{table}}, $table);
}

$xml->{login}->{user} = $user;
$xml->{login}->{password} = $password;

$xml->save('./tables.xml');

sub login {
$dbh = DBI->connect($conn_str, $user, $password)
or die ("Could not make connection to database: $DBI::errstr");
}

sub logoff {
$dbh->disconnect();
}

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/82392/viewspace-144673/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2004-05-31

  • 博文量
    121
  • 访问量
    106597