July 10th, 2014, 12:33 AM
Output .Resx From .CS
.CS contains string within double quotes and I am trying to extract these strings into .resx file.
The existing code output the .resx but with only one string whereas .CS file contains more than one strings in quotes.
Can you please provide any reference to achieve this?
#user input: [Directory]
my $wrkdir = getcwd;
system "attrib -r /s";
print "Processing $wrkdir\n";
find( \&recurse_src_path, $wrkdir );
my $file = $File::Find::name;
my $fname = $_;
if ( ( -f $file ) && ( $file =~ /.*\.cs$/i ) )
open( FILE, $file ) || die "Cannot open $file:\n$!";
while ( $line = <FILE> )
if ( $line =~ s/\"(.*?)\"/$1/m )
push( @lines, $line );
my $nl = '0';
my $output = new IO::File(">Test.resx");
#binmode( $output, ":encoding(utf-8)" );
my $writer = XML::Writer->new(
OUTPUT => $output,
DATA_MODE => 1,
DATA_INDENT => 2
foreach my $r ($line)
$writer->startTag( 'data', name => $_ );
July 10th, 2014, 11:26 AM
You're reopening your output file for every line that matches your regex pattern which means that you're over writing the file each time.
Your foreach my $r ($line) block is "looping" over a scalar which means that it only has 1 iteration. Putting those statements in a foreach block that only iterates once doesn't make any sense.
Using File::Find::Rule would be a better choice to filter on the .cs files.
Last edited by FishMonger; July 10th, 2014 at 11:29 AM.