Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I like the test harness of 2teez, it is easily adapted for a perl -p command line. So I'll reuse it for an old sed-der comment/observation:

For mass transformations of text, trade off flexible regex for static strings when possible.

while (<DATA>) { s/\b module \s+ OLD \b/module NEW/xms; print $_; }
__DATA__ //Verilog HDL for "tt", "hh" "functional" // if i write the word module here the script goofs up `timescale 1ps/10fs module OLD(Y, A, B ); // This is a great module! output Y; input A; input B; endmodule
//Verilog HDL for "tt", "hh" "functional" // if i write the word module here the script goofs up `timescale 1ps/10fs module NEW(Y, A, B ); // This is a great module! output Y; input A; input B; endmodule

Of course, this means that whatever whitespace separation you used to have between the keyword "module" and the module name is gone, but whitespace niceties usually aren't a big deal with mechanically gunkulated code. On the other hand, you don't have to ignore any lines that have commenting on them.

This is a line oriented solution, so slurping in a file and transforming that long string will require using the "g" flag and listening to sages such as choroba. For line-oriented text, I believe line oriented processing gives the fewest surprises (e.g., a surprise such as having a comment change affect code manipulation). However if the two adjacent words you are keying off of can be separated by a newline, then you have to use something like the fancier regex solutions suggested.

One thing left to worry about is whether "module OLD" in a comment should be transformed to "module NEW". But if you keep in mind the old maxim, "All comments lie," then you shouldn't worry too much ;-)


In reply to Re: Bug in script, regex help req extreme urgent by jaredor
in thread Bug in script, regex help req extreme urgent by sid.verycool

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

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

    No recent polls found