[英]How to modify a perl script to read excel instead of Html files
My first question is:我的第一个问题是:
Is this possible to do this, since now I have a perl script which reads Html file and extract data to display on another html file.
这是否可能做到这一点,因为现在我有一个 perl 脚本,它读取 Html 文件并提取数据以显示在另一个 html 文件上。
If the answer for the question above is Yes, my second question would be:如果上述问题的答案是肯定的,那么我的第二个问题将是:
How to do this?
这该怎么做?
Sorry to ask frankly as this, but since I'm so new for perl, and I have to take this task, so I'm here for some useful advice or suggestion to guide me through this task.很抱歉坦率地问这个问题,但由于我对 perl 很陌生,我必须接受这项任务,所以我在这里寻求一些有用的建议或建议来指导我完成这项任务。 Appreciate your help in advance.
提前感谢您的帮助。
Here's a part of the code, since the whole chunk is quite long:这是代码的一部分,因为整个块很长:
$date=localtime();
($TWDAY, $TMTH, $TD1D, $TSE, $TYY) = split(/\s+/, $date);
$TSE =~ s/\://g;
$STAMP=_."$TD1D$TMTH$TYY";
@ServerInfo=();
#--------------------------------------------------------------------------- -------------------------------
# Read Directory
#----------------------------------------------------------------------------------------------------------
$myDir=getcwd;
#----------------------------------------------------------------------------------------------------------
# INITIALIZE HTML FORMAT
#----------------------------------------------------------------------------------------------------------
&HTML_FORMAT;
#----------------------------------------------------------------------------------------------------------
# REPORT
#----------------------------------------------------------------------------------------------------------
if (! -d "$myDir/report") { mkdir("$myDir/report");};
$REPORTFILE="$myDir/report/checkpack".".htm";
open OUT,">$REPORTFILE" or die "\nCannot open out file $REPORTFILE\n\n";
print OUT "$Tag_Header";
#----------------------------------------------------------------------------------------------------------
sub numSort {
if ($b < $a) { return -1; }
elsif ($a == $b) { return 0;}
elsif ($b > $a) { return 1; }
}
@ArrayDir = sort numSort @DirArray;
#while (<@ArrayDir>) {
@OutputDir=grep { -f and -T } glob "$myDir/*.htm $myDir/*.html";
#}
#----------------------------------------------------------------------------------------------------------
@ReadLine3=();
$xyxycnt=0;
foreach $InputFile (@OutputDir) { #---- MAIN
$filename=(split /\//, $InputFile) [-1]; print "-"x80 ; print "\nFilename\t:$filename\n";
open IN, "<$InputFile" or die "Cannot open Input file $InputFile\n";
@MyData=();
$DataCnt=0;
@MyLine=();
$MyLineCnt=0;
while (<IN>) {
$LINE=$_;
chomp($LINE);
$LINE=~s/\<br\>/XYXY/ig;
$LINE=~s/\<\/td\>/ \nXYZXYZ\n/ig;
$LINE=~s/\<dirname\>/xxxdirnameyyy/ig;
$LINE=linetrim3($LINE);
$LINE=linetrim($LINE);
$LINE=~s/XYXY/\<br\>/ig;
$LINE=~s/xxxdirnameyyy/< dirname >/ig;
$LINE=~s/^\s+//ig;
print OUT2 "$LINE\n";
if (defined($LINE)) { $MyData[$DataCnt]="$LINE"; $DataCnt++ ; }
}
close IN;
foreach $ReadFile (@MyData) { #--- Mydata
$MyLineCnt++;
$MyLine[$MyLineCnt]="";
#### FILENAME
$ServerInfo[0]="$filename";
#### IP ADDRESS
if ($ReadFile =~ /Host\/Device Name\:/) {
#print "$ReadFile\n"
($Hostname)=(split /\:|\s+/, $ReadFile)[3]; print "$Hostname\n";
&myServerInfo("$Hostname","1");
}
if ($ReadFile =~ /IP Address\(es\)/) {@ListIP=(); $SwIP=1; $CntIP=0 ; };
#### OPERATING SYSTEM & VERSION
if ($ReadFile =~ /Operating System\:/) {
$SwIP=0;
$OS= (split /\:|\s+/, $ReadFile)[3]; &myServerInfo("$OS","3") ; print "$OS\n";
$OSVer= (split /\:|\s+/, $ReadFile)[-2]; &myServerInfo("$OSVer","4") ; print "$OSVer\n";
};
#### GET IP VALUE
if ($SwIP==1) {
$ReadFile=(split /\:/,$ReadFile) [2];
$ReadFile=~s/[a-z|A-Z]|\(|\)|\// /ig; print "$ReadFile\n";
if ($CntIP==0) {
#$ListIP[$CntIP]=(split /\s+/,$ReadFile) [1];
@ListIP="$ReadFile";
} elsif ($CntIP==1) { print "\n\t\t $ReadFile\n" ; $ListIP[$CntIP]="\n$ReadFile";
} else { print "\t\t $ReadFile\n" ; $ListIP[$CntIP]="\n$ReadFile"; };
$CntIP++;
}
I'm afraid if you don't understand what is going on in this program and you also don't understand how to approach a task like this at all, Stack Overflow might not be the right place to get help.恐怕如果您不了解该程序中发生的事情,并且根本不了解如何处理这样的任务,Stack Overflow 可能不是寻求帮助的正确地方。
Let me try to show you the approach I would take with this.让我尝试向您展示我将采用的方法。 I'm assuming there is more code.
我假设有更多的代码。
Also add use strict
and use warnings
while you refactor to catch errors more easily.还要在重构时添加
use strict
和use warnings
以更轻松地捕获错误。 If stuff breaks because of that, make it work before you continue.如果事情因此而中断,请在继续之前使其工作。 Those pragmas tell you what's wrong.
这些 pragma 会告诉您出了什么问题。 The most common one you will encounter is Global symbol "$foo" requires explicit package name .
您将遇到的最常见的一种是全局符号“$foo”需要明确的包名称。 That means you need to put
my
in front of the first assignment, or declare the variable before.这意味着您需要将
my
放在第一个赋值的前面,或者在此之前声明变量。
If you have specific questions, ask them as a new question with a short example.如果您有具体问题,请用一个简短的示例将它们作为新问题提出。 Read how to ask to make sure you will get help on those.
阅读如何提出要求以确保您能得到这些方面的帮助。
Good luck!祝你好运!
After seing your comment I am thinking you want a different input and a different output.看到您的评论后,我认为您想要不同的输入和不同的输出。 In that case, disregard this, throw away the old code and start from scratch.
在这种情况下,忽略这一点,扔掉旧代码并从头开始。 If you don't know enough Perl, get a book like Curtis Poe's Beginning Perl if you already know programming.
如果您对 Perl 的了解还不够多,那么如果您已经了解编程,那么请阅读 Curtis Poe 的Beginning Perl 之类的书。 If not, check out Learning Perl by Randal L. Schwartz.
如果没有,请查看 Randal L. Schwartz 的Learning Perl 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.