View Single Post
  #3 (permalink)  
Old June 19th, 2009, 11:52 AM
Nagaraj Nagaraj is offline
Authorized User
 
Join Date: Apr 2009
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Cider,

Code:
#!/usr/bin/perl

use strict;

my $directory = "D:/Nagaraj/oup/OUP-Brenkert/Preprocessed";

use File::Find;
use strict;
        
my $count;
my $s;
my $nb;
my $cou;
my $i;
my $ss;
my $tag;

#my $directory = "";

find (\&process, $directory);

sub process
{
    my @outLines;  #Data we are going to output
    my $Replace;      #Data we are reading line by line

        #print "processing $_ / $File::Find::name\n";

    # Only parse files that end in .xml
    if ( ($File::Find::name =~ /\.XML$/) || ($File::Find::name =~ /\.xml$/)) {

        open (FILE, $File::Find::name ) or die "Cannot open file: $!";

        while ( $Replace = <FILE> ) {

                $cou =~ s/<tableGroup([^>]+)<\/tableGroup>/<tableGroup$1<\/tableGroup>/gi;
                        for($i=0;$i<=$cou;$i++)
                                {
                                    if(/(<tableGroup([^>]+)<\/tableGroup>)/)
                                    {
                                            $ss=$1;
                                            $count = ($ss =~ s/<row/<row/g);
                                            $Replace =~ s/<tgroup cols\="(.*?)">/<tgroup cols\="$1"><SPiTable><SPiTable-body xmlns\:aid\="http:\/\/ns.adobe.com\/AdobeInDesign\/4.0\/" aid\:table\="table" aid\:trows\="$count" aid:tcols="$1">/g;
                                            print $count;
                                   }

                                }
              #$Replace =~ s/&ndash;/&#x2013;/g;
              push(@outLines, $Replace);
              }

        close FILE;
        open ( OUTFILE, ">$File::Find::name" ) or
        die "Cannot open file: $!";

        print ( OUTFILE @outLines );
        close ( OUTFILE );

        undef( @outLines );
           }
        }
I tried my best in the above perl script but it not count and replace the string.

You may corrrect this.........?????????
Reply With Quote