Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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 ( [id://1232086]=note: print w/replies, xml ) Need Help??


in reply to Re^2: 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

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!
  • Comment on Re^3: How to add a new line after three or four lines from a pattern after getting that pattern
  • Select or Download Code

Replies are listed 'Best First'.
Re^8: How to add a new line after three or four lines from a pattern after getting that pattern
by anirbanphys (Beadle) on Apr 03, 2019 at 13:44 UTC
    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,

        Please do not worry, I have managed it at the beginning :). It is good to see that you are an perfectionist :).

        Thanks and Best Regards

        Anirban

Re^6: How to add a new line after three or four lines from a pattern after getting that pattern
by anirbanphys (Beadle) on Apr 03, 2019 at 12:57 UTC
    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!
Re^5: How to add a new line after three or four lines from a pattern after getting that pattern
by anirbanphys (Beadle) on Apr 03, 2019 at 12:13 UTC
    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 :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-16 16:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found