- 论坛徽章:
- 0
|
原帖由 flw 于 2008-11-19 13:43 发表
还没了解就开始批判了啊。
这可不是面对新事物所应有的态度。
我觉得 Perl 的面向对象功能很够用,虽然是后来加的,但很巧妙很灵活,并不生硬。
说得对啊, 我用过JAVA, 但是觉得不方便.
PERL的对象, 可以直接把XML的数据读出来,做个HASHTABLE, 直接放到对象里, 方便极了~~~~~~~~~~~~~~~~~~~~~~~~~~~~
package Manage:C;
#file: Manage/PC.pm
#utility routines for testing machine operation.
#do() are only exported functions
use strict;
use Expect;
use XML::Simple;
use XML::XPath;
use XML::XPath::XMLParser;
use Data:umper;
use vars '@ISA', '@EXPORT';
require Exporter;
@ISA = 'Exporter';
@EXPORT = qw();
sub new {
my $class = shift;
my $pc_id = shift;
my $xml = new XML::Simple;
my $data = $xml->XMLin("/home/automation/htang/devices.xml"
my $self = $data->{'PC-LIST'}->{'PC'}->{"$pc_id"};
# print Dumper($self), "\r\n", $class, "\r\n", $pc_id, "\r\n";
bless($self, $class);
return $self;
}
sub do_rsh{
my $timeout = 20;
my $cmd = "rsh";
my $password = "password";
my $self = shift;
my @arg = @_;
print "action do!", @arg;
my $mgt_ip = $self->{'MGT-IP'};
my $exp = Expect->spawn($cmd, $mgt_ip, @arg) or die "Can't spawn $cmd!";
# $exp->debug(1);
$exp->expect($timeout,-re=>'[Pp]assword:');
$exp->send("$password\r\n"
# $exp->expect($timeout,-re=> eof );
$exp->soft_close();
}
sub do_ssh{
my $timeout = 20;
my $cmd = "rsh";
my $password = "password";
my $self = shift;
my @arg = @_;
print "action do!", @arg;
my $mgt_ip = $self->{'MGT-IP'};
my $exp = Expect->spawn($cmd, $mgt_ip, @arg) or die "Can't spawn $cmd!";
# $exp->debug(1);
$exp->expect($timeout,-re=>'[Pp]assword:');
$exp->send("$password\r\n"
# $exp->expect($timeout,-re=> eof );
$exp->soft_close();
}
sub vlan{
my $self = shift;
if (@_) { $self->{"INTERFACE-LIST"}->{"INTERFACE"}->{"eth1"}->{"VLAN"} = shift }
print Dumper($self), "\r\n";
return $self->{"INTERFACE-LIST"}->{"INTERFACE"}->{"eth1"}->{"VLAN"};
}
1;
[ 本帖最后由 thy3368 于 2008-11-24 15:01 编辑 ] |
|