in reply to Need to save a single line from delete on some special condition

Hello anirbanphys. Is the format of your file some kind of standard? If so, I'd recommend trying to find a module that does what you want. Parsing that kind of data (nested) is complex if you want to do it correctly. Otherwise you have to assume some things to "cheat". For example ways you could divide your file into pins would be to either:

There are probably other possibilities, but the implementation I can think of that are simple could be broken by having one of those assumptions proven wrong.

  • Comment on Re: Need to save a single line from delete on some special condition

Replies are listed 'Best First'.
Re^2: Need to save a single line from delete on some special condition
by anirbanphys (Beadle) on Mar 26, 2019 at 11:15 UTC

    Thank you Eily for looking and understanding the issue.

    Yes the three assumptions you mentioned are accurate. I am trying a simple solution "read a line, don't print it when conditions are met" won't work with my new requirement, as "timing(" occurs after the line I want to delete. I'll have to rewrite the code to read one whole " pin(..) { ... }" section in, decide which lines to delete and then dump it to the output. As I have several block-type statements I will either need to count the open brackets or write a real parser for the given syntax. And This is getting complex

    I am using the code, but every time I am getting the issue "timing event not found", what is wrong here?

    perl -0777 -ne ' s/(pin\s*\(".+?"?\)\s+\{.+?\})/$x=$1;if($x=~m!timing +\s*\(\)! and $x=~m!direction : output!){$x=~s!^\s*max_transition.+?\n +!!mg};$x/gse ; print ' <INPUT_FILE>

      the three assumptions you mentioned are accurate
      If you're really sure about the indentation something like that can help :
      use strict; use warnings; use v5.10; my $data = do { local $/; <DATA> }; my @sections = split /(\s{4}pin.*?\s{4}\})/s, $data; for (@sections) { say; say '-' x 24; } __END__ cell (lib_1) { dont_use : true ; dont_touch : true ; pin ("HIZIBI_IN_1") { direction : input ; clock : true ; max_transition : 1 ; capacitance : 12 ; } pin ("HIZIBI_79") { direction : output ; max_transition : 10; min_capacitance : 3 ; } pin ("HIZIBI_IN_1") { direction : input ; clock : true ; max_transition : 1 ; capacitance : 1 ; } pin ("HIZIBI_78") { direction : output ; max_transition : 10; min_capacitance : 34 ; capacitance : 34 ; } pin ("HIZIBI") { direction : output ; clock : true ; max_transition : 20; related_power_pin : VDD ; related_ground_pin : VSS ; timing () { cell_fall (into_f1) { index_1("1,2,3,4,5") ; index_2("1,2,3,4,5") ; values("13, 13, 14, 16, 18",\ "13, 14, 15, 16, 19",\ "14, 15, 16, 17, 20",\ "15, 15, 16, 18, 20",\ "15, 16, 17, 18, 21") ; } } } }
      It's very rough, and assumes a very consistent indentation. It divides the input into section (even empty ones between the pins but that shouldn't be an issue):
      cell (lib_1) { dont_use : true ; dont_touch : true ; ------------------------ pin ("HIZIBI_IN_1") { direction : input ; clock : true ; max_transition : 1 ; capacitance : 12 ; } ------------------------ ------------------------ pin ("HIZIBI_79") { direction : output ; max_transition : 10; min_capacitance : 3 ; } ------------------------ ------------------------ pin ("HIZIBI_IN_1") { direction : input ; clock : true ; max_transition : 1 ; capacitance : 1 ; } ------------------------ ------------------------ pin ("HIZIBI_78") { direction : output ; max_transition : 10; min_capacitance : 34 ; capacitance : 34 ; } ------------------------ ------------------------ pin ("HIZIBI") { direction : output ; clock : true ; max_transition : 20; related_power_pin : VDD ; related_ground_pin : VSS ; timing () { cell_fall (into_f1) { index_1("1,2,3,4,5") ; index_2("1,2,3,4,5") ; values("13, 13, 14, 16, 18",\ "13, 14, 15, 16, 19",\ "14, 15, 16, 17, 20",\ "15, 15, 16, 18, 20",\ "15, 16, 17, 18, 21") ; } ------------------------ } } } ------------------------

      Edit: it also assumes that the file is not so big that you can't read it all at once.

        Thank you for helping me.

        Now I need to find "direction : output", so we have here for pin HIZIBI_79, HIZIBI_78 and HIZIBI. But only pin HIZIBI is containing "timing" group, so for this pin we need to delete "max_transition" line and have to print the final output put file. Please refer OUT_FILE at he beginning of the post. And pin name can be anything.

        Can we add the logic inside foreach loop?