On 11/16/10 Tue  Nov 16, 2010  9:01 AM, "Vincent Li"
<[email protected]> scribbled:

> Hi List,
> 
> I have a text test.txt file looks like below:
> 
> stp instance 0 {
>    interfaces 1.1 {
>          external path cost 20000
>          internal path cost 20000
>       }
>    vlans {
>       internal
>       vlan10
>    }
> }
> profile http http_global {
>    defaults from http
>    max header size 38912
>    encrypt cookies {
>       "F-P-SES"
>    }
> }

[snip]

> how can I find a specific profile { } block and remove/replace that
> part from the file, for example, I want to remove below block or
> replace it with emtpy blank line
> 
> profile tcp tcp {
>    reset on timeout enable
>    time wait recycle enable
>    delayed acks enable
>    proxy mss disable
> }
> 
> and the { } could have nested { } block too.
> 

You need a parser to do this right. You might have some luck by reading the
entire file into a scalar variable and using the Text::Balanced module
together with some regular expressions to extract and parse the various
blocks within the file.

A more rigorous approach would be to create a real parser with the
Parse::RecDescent module and create a grammar for your file. However, that
module has a steep learning curve and can be slow.



-- 
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to