1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Rep Power

    Output .Resx From .CS

    Hi All,

    .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?

    use strict;
    use warnings;
    use File::Find;
    use XML::Writer;
    use Cwd;
    #user input: [Directory]
    my $wrkdir = getcwd;
    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> )
    			if ( $line =~ s/\"(.*?)\"/$1/m )
    				chomp $line;
    				push( @lines, $line );
    				my $nl = '0';
    				my $dataIndent;
    				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)
    					print "$1\n";
    					$writer->startTag( 'data', name => $_ );
    		close FILE;

  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Apr 2009
    Rep Power
    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 10:29 AM.

IMN logo majestic logo threadwatch logo seochat tools logo