Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: 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 11:35 UTC ( [id://1232080]=note: print w/replies, xml ) Need Help??


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") { " . Can you please review the code

#!/usr/bin/perl use strict; use warnings; use IO::All; use Data::Dumper; use feature 'say'; my @operating_cond; my @lines = io('file.txt')->chomp->slurp; #print Dumper \@lines; for my $i (0 .. $#lines) { if ($lines[$i] =~ /operating_conditions/) { #print "$lines[$i]\n"; @operating_cond=split (operating_conditions,$lines[$i]); @operating_cond=split ("{",$operating_cond[1]); @operating_cond=split (/\(/,$operating_cond[0]); @operating_cond=split (/\)/,$operating_cond[1]); # Insert at position 12, replace 0 elements. splice @lines, $i + 5, 0, 'default_operating_conditions : "@operat +ing_cond" ;'; last; # break loop } next; } print Dumper \@lines;

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:47 UTC

    Hello again anirbanphys,

    See the updated version that contains solution to the hard-coded problem. Now the script will pick up the string withing the interesting line.

    Hope this helps. Let me know if you can not understand what the code does.

    BR / Thanos

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

      SURE !!! Yes I just got the code :D. And it is working. I commented the unwanted section. One Last help, how to get rid of from extra characters from the output? Do I have to parse again to delete the extra characters?

        Hello again anirbanphys,

        I do not know what extra characters from the output you are referring? If you mean the single quotes '' in the output it simply how Data::Dumper prints the output. If you want you can use alternatively:

        use feature 'say'; say $_ for @lines;

        Otherwise give me more information regarding the characters you want to remove. BR / Thanos

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-24 19:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found