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
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 :)
|
|---|
| 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 | |
by anirbanphys (Beadle) on Apr 03, 2019 at 11:53 UTC | |
by thanos1983 (Parson) on Apr 03, 2019 at 12:05 UTC |