Advertisement
Guest User

Untitled

a guest
Oct 12th, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. cell ( identifier ) {
  2. keyword2 { };
  3. ...
  4. keyword3 { keyword4 { } };
  5. }
  6.  
  7. ...more sections...
  8.  
  9. #!/usr/bin/perl -w
  10.  
  11. use strict;
  12.  
  13. my $input_file = "input";
  14. open FILE, "<$input_file" or die $!;
  15.  
  16. my $in_block = 0;
  17. my $current_block = '';
  18. my $open_bracket_count = 0;
  19. while( my $line = <FILE> ) {
  20. if ( $line =~ /cell/ ) {
  21. $in_block = 1;
  22. }
  23.  
  24. if ( $in_block ) {
  25. while ( $line =~ /([{}]{1})/g ) {
  26. my $token = $1;
  27. if ( $token eq '{' ) {
  28. $open_bracket_count++;
  29. } elsif ( $token eq '}' ) {
  30. $open_bracket_count--;
  31. }
  32. }
  33.  
  34. $current_block .= $line;
  35. }
  36.  
  37. if ( $open_bracket_count == 0 && $current_block ne '' ) {
  38. print '-' x 80, "n";
  39. print $current_block, "n";
  40. $in_block = 0;
  41. $current_block = '';
  42. }
  43. }
  44. close FILE or die $!;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement