提取物替换.CS文件中的字符串

时间:2014-09-16 05:38:49

标签: perl

我正在尝试从文件夹和子文件夹中存在的* .cs文件中提取字符串,并在双引号中显示字符串,并使用值写入.resx文件,注释包含提取的字符串。此外,数据属性名称应包含classname_methodname_id ### [001 ..]。你可以提供任何参考递归文件和文件夹来搜索.CS文件并添加而不是提取的字符串替换为" Properties.Resources.classname_methodname_incremental number"

我现有的代码如下...

use strict;
use warnings;
use File::Find;
use XML::Writer;
use Cwd;

#user input: [Directory]
my $wrkdir = $ARGV[0];

system "attrib -r /s";
print "Processing $wrkdir\n";

find( \&recurse_src_path, $wrkdir );

sub recurse_src_path {
    my $file = $File::Find::name;
    my $fname;
    my @lines;
    my $line;
    if ( ( -f $file ) && ( $file =~ /.*\.cs$/i ) ) {
        print "..";
        open( FILE, $file ) || die "Cannot open $file:\n$!";
        while ( $line = <FILE> ) {
            while ( $line =~ /\"(.*)\"/g ) {
                push( @lines, $1 );
                print "Found quoted string: '$1'\n";
                my $nl = '0';
                my $dataIndent;
                my $output = new IO::File(">Resources.resx");
                #binmode( $output, ":encoding(utf-8)" );
                my $writer = XML::Writer->new(
                    OUTPUT      => $output,
                    DATA_MODE   => 1,
                    DATA_INDENT => 2
                );
                $writer->xmlDecl("utf-8");
                $writer->startTag('root');
                foreach (@lines) {
                    $writer->startTag( 'data', name => $file );
                    $writer->startTag('value');
                    $writer->characters($_);
                    $writer->endTag('value');
                    $writer->startTag('comment');
                    $writer->characters($_);
                    $writer->endTag('comment');
                    $writer->endTag('data');
                }
                $writer->endTag('root');
                $writer->end;
                $output->close();
            }
        }
    }
    close FILE;
}

谢谢&amp;问候, ShailShin

0 个答案:

没有答案