Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

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

Hi, you want to use a substitution regex operator. the match operator is described as m//, this is the operator you have used. The substition operator is described s///.

The pattern you wish to match goes in the first section as per a normal match, the pattern you wish to replace in the second section. You can use parentheses in the first section to capture the matched pattern and reuse it in the second section within the special variables $1 through $9

if ($_ =~ /start ux/){ print "#$_"; }

(assuming the whole line is a pattern match) becomes...

s/(pattern)/#$1/;

if you wanted to insert an octothorpe if the pattern matches anywhere in the line, you could have your regex match the whole line if part of it matches...

s/^(.*(pattern).*)$/#$1/;

regex operates on the $_ variable, and substitution matching is an 'if' operation in itself. In this case the parentheses match in subsequential order from first open through to second open (pattern matches $2). The outer characters say, anything matches.


s/(Coy)/$1ote/;

In reply to Re: Write to existing file with character insert by Don Coyote
in thread Write to existing file with character insert by Mark.Allan

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 wandering the Monastery: (6)
As of 2024-04-26 08:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found