SPUG: Removing newlines from a multi-line string

David Vergin dvergin at igc.org
Wed Mar 14 03:41:18 CST 2001


If you are on Windows, you are dealing with two characters at the end of each
line: \r and \n.
(And you don't need /i (case-insensitive matches)). So try:

    $html =~ s/[\n\r]//g;

dv

> -----Original Message-----
> From: owner-spug-list at pm.org [mailto:owner-spug-list at pm.org]On Behalf Of
> Joshua Lanza
> Sent: Wednesday, March 14, 2001 12:01 AM
> To: spug-list at pm.org
> Subject: SPUG: Removing newlines from a multi-line string
>
>
> Hi all,
>
> I have a script that gets a chunk of HTML from an access database and plunks
> it into a template.  The problem is that it puts newline characters in the
> HTML at the end of every line in the HTML blob, which is (1) unseemly and
> (2) making it difficult to manipulate the text after the pages are
> generated.
>
> I store the text in $html and then try
>
>         $html =~ s/\n//ig;
>
> but nothing seems to happen.  If this worked it would solve (2) from above
> but wouldn't help (1).  I guess what I'm really looking for is why I'm
> getting the extra newlines in the first place.  Any thoughts greatly
> appreciated,
>
> Josh
>
>
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com
>
>
>  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>      POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
>       Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
>   Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
>  For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
>   Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
>
>


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/





More information about the spug-list mailing list