Perl查找资源文件

这几天做一个本地化项目,翻译组要做log纪录很累,以前直听说Perl文本处理的功能很强,一时兴起,就现学现用用perl为他们写了个自动抓取变更纪录的perl程序,发现Perl真的很强大,程序如下:

#!/usr/bin/perl -w
use encoding 'UTF-8', STDIN =>'UTF-8', STDOUT =>'UTF-8';
use strict;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';

$Win32::OLE::Warn = 3;

#define some parameters
my $LogFilePath="E:/PickUpString/Change Log.xls";
my $excelRowStart=722;
my $excelRowEnd=773;
my $excelCol=2;
my $excelSheet=1;
my $rcFile="legacy";
my $rcPath="F:/RC/NewRC/";
my $rcOldPath="F:/RC/OldRC/";
#end define

my $Excel = Win32::OLE->GetActiveObject('Excel.Application')
    || Win32::OLE->new('Excel.Application', 'Quit');
   
my $Book = $Excel->Workbooks->Open($LogFilePath);

my $Sheet = $Book->Worksheets($excelSheet);

my $stringId="";

foreach my $row ($excelRowStart..$excelRowEnd)
{
    $stringId=GetStringID($Sheet->Cells($row,$excelCol)->{'Value'},"${rcPath}${rcFile}.rid");
       
    $Sheet->Cells($row,$excelCol+1)->{'Value'}=GetCaption($stringId,
                                                          "${rcOldPath}(SChinese)${rcFile}.rc");
    $Sheet->Cells($row,$excelCol+2)->{'Value'}=GetCaption($stringId,
                                                          "${rcPath}(SChinese)${rcFile}.rc");
    $Sheet->Cells($row,$excelCol+3)->{'Value'}=GetCaption($stringId,
                                                          "${rcPath}${rcFile}.rc");  
}

$Book->Close;

sub GetStringID
{
    my ($id,$filePath)=@_;
    my $strValue;
    open(FILE,$filePath) || die "$filePath not exists" ;
     
    while(my $line=<FILE>)
    {
        if($line=~/$id/)
        {
            $line=~/\s.*\s[^\d]/;
            $strValue=$&;
            $strValue=~s/\s//g;
            last;
        }
    }
   
    close(FILE);

    return $strValue;
}

sub GetCaption
{
    my ($StringID,$filePath)=@_;
    my $strValue;
      
    open(FILE,$filePath) || die "$filePath not exists" ;

    while(my $line=<FILE>)
    {
        if($line=~/$StringID/)
        {
            $line=~/\".*\"/;
            $strValue=$&;
            last;
        }
    }
   
    close(FILE);
   
    return $strValue;
}

首先从Excel里将ID编号取出来,然后到资源文件中查找对应编号的资源,注此程序只能查找TableString的值。

短短的几十行代码,完成这样的功能使我对脚本语言刮目相看,以后决定好好研究一下脚本语言。

posted on 2007-01-09 20:56 申松淦 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/yzssg/archive/2007/01/09/616148.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值