Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I'm somewhat lazy so
#!/usr/bin/env perl use Data::Dumper; use Regexp::Common; use 5.12.0; my $library_group_re=qr{ library\ * # "library" follow +ed by optional spaces ( # $1 capture (?<paren>$RE{balanced}{-parens=>'()'}) # balanced parenth +esis \ * # followed by opti +onal spaces (?<braces>$RE{balanced}{-parens=>'{}'}) # balanced braces ) # end $1 capture }x; my $operating_conditions_group_re=qr{ operating_conditions\ * # "operating_condi +tions" followed by optional spaces ( # $1 capture (?<paren>$RE{balanced}{-parens=>'()'}) # balanced parenth +esis \ * # followed by opti +onal spaces (?<braces>$RE{balanced}{-parens=>'{}'}) # balanced braces ) # end $1 capture }x; sub do_something_with_an_operating_conditions { #warn Data::Dumper->Dump([\@_],[qw(*_)]),' '; my (%captured)=@_; if (!exists $captured{paren} || ! exists $captured{braces}) { die "Should NOT happen!"; }; my $return='operating_conditions '; # process the stuff within the parenthesis - $return.="$captured{paren} "; # process the stuff within the braces $return.="$captured{braces}"; # The additional line. $return.="\n default_operating_conditions : ".substr($captured +{paren},1,-1)."\n"; return $return; }; sub do_something_with_a_library { #warn Data::Dumper->Dump([\@_],[qw(*_)]),' '; my (%captured)=@_; if (!exists $captured{paren} || ! exists $captured{braces}) { die "Should NOT happen!"; }; my $return='library '; # process the stuff within the parenthesis - $return.="$captured{paren}"; # process the stuff within the braces - operating conditions { (my $string=$captured{braces})=~ s{$operating_conditions_gr +oup_re}{do_something_with_an_operating_conditions(%+)}gex; $return.=" $string"; }; return $return; }; my $string; { # Because we want all of the data as a single string local $/; # Deal with string, which will be the entire file, replacing each +of library groups ($string=<DATA>) =~ s{$library_group_re}{do_something_with_a_libra +ry(%+)}gex; } print $string; __END__ 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 ; } input_voltage(default) { vi : 0 ; vh : 0.5 ; vim : 0 ; vin : 0.5 ; } }

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (6)
    As of 2019-12-06 20:09 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Strict and warnings: which comes first?



      Results (159 votes). Check out past polls.

      Notices?