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??
$data =~ y/\n/ /; # This will remove all newlines and replace them wit +h spaces
Better still, if you want to replace all the greater than one space(s) in your regular expression and take care of any newlines that you have at the time, you can do so with this RegEx:
$data =~ s/\s+|\n/ /g;
The main key here is that \s* has been replaced with \s+, so it's no longer greedy and will replace only multiple space characters.

The difference between s and m is that s is used to substitue an expression, whilst m is used to test for a pattern match. M is not really used too much as it is implied when you place a regular expression between two slashes (ie. $data =~ /\n/g is the same as $data=~ m/\n/g). The y modifier is a simple character replacement (transliteration).

Update: With much thanks to Enlil for the explaination, the whole regex could actually be written without the \n (i.e. $data =~ s/\s+/ /g).


In reply to Re: multi line matching problem by SquireJames
in thread multi line matching problem by jcpunk

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.