Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cell ( identifier ) {
- keyword2 { };
- ...
- keyword3 { keyword4 { } };
- }
- ...more sections...
- #!/usr/bin/perl -w
- use strict;
- my $input_file = "input";
- open FILE, "<$input_file" or die $!;
- my $in_block = 0;
- my $current_block = '';
- my $open_bracket_count = 0;
- while( my $line = <FILE> ) {
- if ( $line =~ /cell/ ) {
- $in_block = 1;
- }
- if ( $in_block ) {
- while ( $line =~ /([{}]{1})/g ) {
- my $token = $1;
- if ( $token eq '{' ) {
- $open_bracket_count++;
- } elsif ( $token eq '}' ) {
- $open_bracket_count--;
- }
- }
- $current_block .= $line;
- }
- if ( $open_bracket_count == 0 && $current_block ne '' ) {
- print '-' x 80, "n";
- print $current_block, "n";
- $in_block = 0;
- $current_block = '';
- }
- }
- close FILE or die $!;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement