in reply to Parsing spaces and curly braces

You probably want a real parser. Off the top of my head, I'd go with a 2-pass approach (assuming no nested curlies):
while (my $line = <>) { chomp($line); while ( length( $line ) ) { if ( my $not_curly = /^([^{]+)/ ) { push @tokens, process_not_curly($not_curly); $line = adjust_line($line, $not_curly); } elsif ( my $curly = /^\{([^}]+)\}/ ) { push @tokens, process_curly($curly); $line = adjust_line($line, $curly); } else { die "can't get here, "; } } }
and you should be able to work out process_not_curly, process_curly, and adjust_line.

Update: After further review, Roy Johnson has the right idea; I need more coffee; I still like my (re)title.

-QM
--
Quantum Mechanics: The dreams stuff is made of

Replies are listed 'Best First'.
Re^2: Parsing spaces and curly braces
by ikegami (Patriarch) on Sep 12, 2005 at 20:02 UTC

    Your parser is really just a tokenizer. m/.../gc lends itself well to writting tokenizers, as seen in the following snippet:

    while (my $line = <>) { chomp($line); my @tokens; foreach ($line) { /\G ( [^{\s]+ )/xgc && do { push(@tokens, $1); redo }; /\G ( {[^}]*} )/xgc && do { push(@tokens, $1); redo }; /\G \s+/xgc; redo; } ...process split line... }

    Cases not specified by the OP behave as follows:

    "xxx{yyy zzz}" is split into "xxx" and "{yyy zzz}".
    "{xxx yyy}zzz" is split into "{xxx yyy}" and "zzz".

Re: Parsing spaces and curly braces
by jonadab (Parson) on Sep 12, 2005 at 19:44 UTC
    You probably want a real parser.

    That's really only necessary if the braces can be nested. If not, a regular expression can handle it, as for example in the above-posted solution.