首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

一个PERL程序帮忙看下解决思路

2012-03-02 
一个PERL程序帮忙看下没搞过perl但项目突然来了个perl 程序不想再去看perl教程了来这求助下大概我是看得懂

一个PERL程序帮忙看下
没搞过perl
但项目突然来了个perl 程序 
不想再去看perl教程了 来这求助下 大概我是看得懂得 只是模糊 我把我的理解写在后面了 希望大虾们正解

$IDPASS = $ARGV[0];

$SAVE_DIR = $ARGV[1] . '/saved';
$WORK_DIR = $ARGV[1] . '/in';
$IN_DATE = $ARGV[2];
$file1 = "ls.lst"; ---上面接受三个参数,这里定义个文件

$call_unix = "ls -t $WORK_DIR/*.txt > $WORK_DIR/$file1";
system($call_unix); ---unix的一些命令

open(IN,"$WORK_DIR/$file1")
  || die "cannot open input file";
  @in_data=<IN>; ---这不太明白,打开文件,然后<>啥意思
close(IN);

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);

if ($sec < 10) {  
  $sec = '0' . $sec;
 }  

if ($min < 10) {  
  $min = '0' . $min;
  }  

if ($hour < 10) {  
  $hour = '0' . $hour;---这里的点是连接符吧??
  }  

if ($mday < 10) {  
  $mday = '0' . $mday;
  }

$mon = $mon + 1;  
if ($mon < 10) {  
  $mon = '0' . $mon;
 }  

$rundate = $year+1900 . $mon . $mday . "_" . $hour . $min . $sec;

foreach $tmp (@in_data) ---循环,但这里的$tmp (@in_data) 不懂 这个tmp哪来的?
{
 chop($tmp);
 $tmp = substr($tmp,27);
 $extension = index($tmp,"txt") - 1;
 $filename = substr($tmp,0,$extension);
 $savedfile = $filename . '_' .$rundate . '.txt'; ---这块需要详细解释下

 $sqlexec = '@cws_loadstaged.sql';
 $call_c = "sqlplus -s $IDPASS $sqlexec $WORK_DIR $tmp $IN_DATE";
 system ($call_c);

 $call_unix = "cp $WORK_DIR/$tmp $SAVE_DIR/$savedfile";
 system ($call_unix);

 $call_unix = "mv $WORK_DIR/$tmp $WORK_DIR/$filename.loaded";
 system ($call_unix);
}  

$call_unix = "rm $WORK_DIR/*.loaded";
system ($call_unix);

$call_unix = "rm $WORK_DIR/$file1";
system ($call_unix);

print "\nCOMPLETED\n";


[解决办法]
@in_data=<IN>; ---这不太明白,打开文件,然后<>啥意思
这个意思是把文件读入到数组中,每行一个元素

foreach $tmp (@in_data) ---循环,但这里的$tmp (@in_data) 不懂 这个tmp哪来的?
这个$tmp是个临时变量,每一次循环取@in_data中的一个元素,即文件中读入的一行

chop($tmp);
 $tmp = substr($tmp,27);
 $extension = index($tmp,"txt") - 1;
 $filename = substr($tmp,0,$extension);
 $savedfile = $filename . '_' .$rundate . '.txt'; ---这块需要详细解释下
文件是读入的应该是文件名,这一段的目的就是把文件名提取出来,在后面加上上期和txt后缀
[解决办法]
$savedfile = $filename . '_' .$rundate . '.txt'; ---这块需要详细解释下

这句话是用来狗在一个文件名,跟前边的"."含义是一样的,进行字符串的连接。

热点排行