我编写了一个 perl 程序,它定期将更新的数据从文件发送到远程服务器。但是现在我希望它从不同的文件中读取它并发送更新的数据,以便接收者应该知道如何将数据与混合数据分开。我只需要放置某种分隔符吗?此类事情是否已有任何标准?
#############
#Change parameters
############
$PeerAddr='192.168.0.7';
$PeerPort='7070';
##############
# Import packages
##############
use Text::Diff;
use IO::Socket;
#############
# Define global variables
#############
$lineCount=0;
$loopCount=0;
our $stats2 = 0;
for($count = 0; $count <= 10000; $count++){
my $data_dir="archive/otat/*dat";
my $data_file= `ls -t $data_dir | head -1`;
chomp($changed_data_file);
print "old data_file is $changed_data_file \n";
chomp($data_file);
if($data_file ne $changed_data_file){
$lineCount2=0;
$changed_data_file=$data_file;
print ("String:$data_file :$changed_data_file are not equal\n");
}
while(defined($data_file)){
print "$data_file \n";
open (DAT,$data_file) || die("Could not open file! $!");
@iofile = <DAT>;
$lineCount = @iofile;
splice(@diffLines);
print "printing: $lineCount\n";
print "printing 2: $lineCount2 \n";
chomp $lineCount;
chomp $lineCount2;
if($lineCount != $lineCount2){
$j=0;
for($i=$lineCount2;$i <= $lineCount; $i++){
$diffLines[$j] = $iofile[$i];
$j++;
}
$num=@diffLines;
print "count of diff lines:$num\n";
$lineCount2 = $lineCount;
$loopCount=0;
}
if($loopCount>2){
$loopCount=0;
print "Look for recent file \n";
last;
}
$loopCount++;
sleep(5);
############################
&socket_con(@diffLines);
}
}
#### Methods/Functions
sub socket_con {
if ($sock== 0){
$sock = new IO::Socket::INET (
PeerAddr => $PeerAddr,
PeerPort => $PeerPort,
Proto => 'tcp'
);
die "Could not create socket: $!\n" unless $sock;
}
print $sock @_;
#close($sock);
}