Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Parsing a file with parentheses to build a hash

by xcellsior (Novice)
on Nov 13, 2014 at 23:49 UTC ( [id://1107164]=note: print w/replies, xml ) Need Help??


in reply to Re: Parsing a file with parentheses to build a hash
in thread Parsing a file with parentheses to build a hash

Oh, quick question. Will I need to barf the entire file into a single var or is there another way to do this? Ex:
#!/path_to_perl use Parse::RecDescent; $::RD_ERRORS = 1; #Parser dies when it encounters an error $::RD_WARN = 1; #Enable warnings - warn on unused rules &c. $::RD_HINT = 1; # Give out hints to help fix problems. my $grammar = <<'END_OF_GRAMMAR'; # What you said... start : '(' section(s) ')' section : '(' id entry(s) ')' entry : '(' section | keypair ')' keypair : '(' key value ')' END_OF_GRAMMAR my $text; while (<BRD>) { my $new_line = $_; chomp; $text = "$text $new_line"; } my $parser = Parse::RecDescent->new($grammar) or die "Ha Ha, something + is wrong with the syntax, good luck finding the issue!\n"; defined $parser->section($text) or die "It helps if there is a section + to find...";

I'm just writing, I havent tested anything yet, so I'm sure there are a few issues still in my understanding:) Starting to read Why won't this basic Parse::RecDescent example work?

Replies are listed 'Best First'.
Re^3: Parsing a file with parentheses to build a hash
by RichardK (Parson) on Nov 14, 2014 at 14:54 UTC

    I'd use File::Slurp read_file, but there are lots of ways to do it.

    use File::Slurp; my $text = read_file( $filename );
      2 lines vs 7 is always a good trade!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1107164]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-20 02:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found