CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate: Re: [Kenosis] Remove lines: Edit Log



Zhris
Enthusiast

Oct 21, 2013, 7:11 PM


Views: 8106
Re: [Kenosis] Remove lines

EDIT: both our versions strip the whitespace ;(. I thought when I tested mine it retained, my mistake. Nice spot though! Probably best to stick to multiple regexps...


Code
$str =~ s/^\s*\n//; 
$str =~ s/\n\s*\n/\n/g;
$str =~ s/\n\s*$//;




Hi Kenosis,

Unfortunately, your modification would strip the whitespace from the beginning of non blank lines, although this might be desirable...


Code
my $str = ' 

this

is

a

test

';


$str =~ s/(^|\n)\s*/$1/g;

print $str;


output:

Code
this  
is
a
test


Chris


(This post was edited by Zhris on Oct 21, 2013, 8:05 PM)


Edit Log:
Post edited by Zhris (Enthusiast) on Oct 21, 2013, 7:12 PM
Post edited by Zhris (Enthusiast) on Oct 21, 2013, 7:15 PM
Post edited by Zhris (Enthusiast) on Oct 21, 2013, 7:15 PM
Post edited by Zhris (Enthusiast) on Oct 21, 2013, 7:20 PM
Post edited by Zhris (Enthusiast) on Oct 21, 2013, 7:22 PM
Post edited by Zhris (Enthusiast) on Oct 21, 2013, 7:25 PM
Post edited by Zhris (Enthusiast) on Oct 21, 2013, 7:46 PM
Post edited by Zhris (Enthusiast) on Oct 21, 2013, 7:53 PM
Post edited by Zhris (Enthusiast) on Oct 21, 2013, 8:03 PM
Post edited by Zhris (Enthusiast) on Oct 21, 2013, 8:05 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives