Hi John,

For checking a 10,0000+ lines, your code cut down the processing time from
30 seconds to a mere 5 seconds, amazing.

Thanks a lot.

On Thu, Jul 28, 2011 at 10:04 PM, John W. Krahn <jwkr...@shaw.ca> wrote:

> newbie01 perl wrote:
>
>> Hi all,
>>
>
> Hello,
>
>
>  I've written a Perl script below that check and report for malformed
>> braces.
>> I have a UNIX ksh version and it took a couple of minutes to run on a
>> 10000+
>> lines. With the Perl version it only took about 20 seconds so I decided to
>> do it the Perl way. Besides I need a similar thing for Windows as well at
>> some stage.
>>
>
> This may work better for you, although the line numbers are the actual line
> numbers, but I'm sure you could adjust them to your liking:
>
> #!/usr/bin/perl
> use warnings;
> use strict;
>
>
> my $fileTNS = shift or die "usage: $0 TNSfile\n";
>
> open my $IN, '<', $fileTNS or die "Cannot open '$fileTNS' because: $!";
>
> my @groups;
> while ( <$IN> ) {
>    next if /\A\s*#/ || !/\S/;
>    if ( /\A([\w.]+)\s*=/ ) {
>        push @groups, [ $., undef, $1, $_ ];
>        }
>    else {
>        $groups[ -1 ][ -1 ] .= $_;
>        $groups[ -1 ][  1 ]  = $.;
>        }
>    }
>
> for my $group ( @groups ) {
>    my ( $start, $end, $tns, $data ) = @$group;
>    print
>        "Checking -> START = $start :: END = $end :: TNS = $tns = = ",
>        $data =~ tr/(// == $data =~ tr/)// ? 'OKAY' : 'MALFORMed !!!',
>        "\n";
>    }
>
> __END__
>
>
> John
> --
> Any intelligent fool can make things bigger and
> more complex... It takes a touch of genius -
> and a lot of courage to move in the opposite
> direction.                   -- Albert Einstein
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>

Reply via email to