in reply to Re: How to add a new line after three or four lines from a pattern after getting that pattern
in thread How to add a new line after three or four lines from a pattern after getting that pattern

Thank you thanos1983 for your help.

The above mentioned code will be working if we remove the "HARD CODED" "default_operating_conditions : "AB0.5v45c" ;". If you look at my code, I am doing some operations for getting "AB0.5v45c" from " operating_conditions ("AB0.5v45c") { " . Like,

splice @lines, $i + 5, 0, 'default_operating_conditions : "$operating_ +cond[0]" ;';
One more thing, how to avoid to print the very first "$VAR1 = [" section?

Thank you for your help :)

  • Comment on Re^2: How to add a new line after three or four lines from a pattern after getting that pattern
  • Download Code

Replies are listed 'Best First'.
Re^3: How to add a new line after three or four lines from a pattern after getting that pattern
by thanos1983 (Parson) on Apr 03, 2019 at 11:51 UTC

    Hello again anirbanphys,

    Regarding the hard-coded part I have already replied to your question :). Regarding the first print simply commend out the line: # print Dumper \@lines;.

    Hope this helps, BR.

    Seeking for Perl wisdom...on the process of learning...not there...yet!
      Hello thanos1983 ,

      It is great to see that continuously you are helping me to improve the skill in perl coding. Yes I added your suggested code in the actual code.

      Thank you for your help :)

      Thanks you and best regards

      Anirban

        Hello again anirbanphys,

        I have added the last update tha contains the full solution. One minor thing that I added is on the string that you add to the array. I noticed from the desired output sample 'default_operating_conditions : "AB0.5v45c" ;' should be '  default_operating_conditions : "AB0.5v45c" ;' I guess? I simply added two white spaces (nothing special).

        If see the updated code if not do not modify it :)

        BR / Thanos

        Seeking for Perl wisdom...on the process of learning...not there...yet!
      Hello thanos1983,

      I am able to print the desired output in a file. Thank you for your help and give me your valuable time to resolve the issue :). Take care :)

      With Best Regards Anirban

        Hello again anirbanphys,

        If you want to write the output to the file in one line you can do it like this:

        io('out.txt')->appendln($_) for @lines; __END__ $ perl test.pl $ cat out.txt library(and_gate) { delay_model : table_lookup ; date : "Fri Mar 15 03:44:39 " ; time_unit : 1ms ; voltage_unit : 1V ; current_unit : 1A ; operating_conditions ("AB0.5v45c") { process : 1 ; temperature : 45 ; voltage : 0.5 ; } default_operating_conditions : "AB0.5v45c" input_voltage(default) { vi : 0 ; vh : 0.5 ; vim : 0 ; vin : 0.5 ; } }

        You can use the method IO::All/appendln from the same package as you do for reading.

        Hope this helps, BR.

        Seeking for Perl wisdom...on the process of learning...not there...yet!
      Hi thanos1983,

      I am very sorry, you have given me the solution but still I am not able to get the desired result. You are correct, I meant single quotes, $var1 as extra characters in the output. But let me check the cpan documentation for the correct way to print it :)