Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 243145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:53:49+00:00 2026-05-11T20:53:49+00:00

I’m trying to parse some data out of a file using Perl & Parse::RecDescent.

  • 0

I’m trying to parse some data out of a file using Perl & Parse::RecDescent. I can’t throw the full data file at the perl script because RecDescent will take days poring over it. So I split up the huge datafile into RD-sized chunks to reduce the runtime.

However, I need to extract sections within balanced brackets and the routine I have now is not robust (it depends too much on the position of the final close-bracket from a newline). Example:

cell ( identifier ) {
  keyword2 { };
  ...
  keyword3 { keyword4 {  } };
}

...more sections...

I need to grab everything from cell ... { to the matching closing } which can have various amounts of spacing and sub-sections.

There must be some linux command line thing to do this easily? Any ideas?

Edit: Input files are around 8M, grammar ~60 rules.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T20:53:49+00:00Added an answer on May 11, 2026 at 8:53 pm

    Why does RecDescent take so long? Is it because your grammar is complex? If that’s the case, you could two a bi-level pass using Parse::RecDescent. The idea is that you would define a simple grammar that parses cell … { … } and then passes parsed output from the first parser into a call to Parse::RecDescent with your more complex grammar. This is guessing about the reason for RecDescent being slow on your data.

    Another option is to write your own simple parser that matches on the cell entries, counts the number of braces it’s seen so far, and then finds the matching brace when the closing brace count is equal to the opening brace count. That should be fast, but the suggestion above might be faster to implement and easier to maintain.

    Edit: You should definitely try Parse::RecDescent with a simplified grammar. The algorithmic complexity of recursive descent parsing is proportional to the number of possible parse trees, which should be something like is B ^ N, where B is the number of branching points in your grammar, and N is the number of nodes.

    If you’d like to try rolling your own simple parser for a first pass over your input, the following code can get you started.

    #!/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 $!;
    

    Edit: changed code to avoid slurping the entire file into memory. While this is trivial for an 8MB file, it’s cleaner to just read the file in line-by-line.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 210k
  • Answers 210k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can't have arrays of size 0, so 1 is… May 12, 2026 at 10:03 pm
  • Editorial Team
    Editorial Team added an answer The .NET FCL doesn't provide a class like java.util.zip.CRC32 so… May 12, 2026 at 10:03 pm
  • Editorial Team
    Editorial Team added an answer The export to pdf should be done on the server… May 12, 2026 at 10:03 pm

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want use html5's new tag to play a wav file (currently only supported
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
In order to apply a triggered animation to all ToolTip s in my app,
I have a French site that I want to parse, but am running into

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.