Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I want to clean a chunk of data into an eye catching format. I tried replacing newlines but an not getting it correct.

What I have now is like this,

$data = '3rd Line Support - Managed Services & Hosting Caerphilly, Wales - Circa 40k DOE + Excellent Company Benefits Permanent Posted: Wednesday, 29 May 2013 3rd Line Support - Managed Services & Hosting Role: Providing support to client's infrastructures and maintaining high ava +ilability through proactive measures Resolving complex server issues escalated by other internal department +s by administration and troubleshooting problems. Ensuring clients & partners are updated on current status of issues Implement operational procedures, tools and best practice as defined i +n corporate business plan Ensure that knowledge is retained through documentation of processes a +nd procedures and implementation of server changes. Updating and maintaining our Knowledge base software. Documenting troubleshooting carried out Ensure all changes are documented through the change management proces +s Execute change management tasks in line with defined processes Assist in the analysis and resolution of problems as raised by the pro +blem management functions';

I want to change it into,

$data = '3rd Line Support - Managed Services & Hosting Caerphilly, Wales - Circa 40k DOE + Excellent Company Benefits Permanent Posted: Wednesday, 29 May 2013 3rd Line Support - Managed Services & Hosting Role: Providing support to client's infrastructures and maintaining high ava +ilability through proactive measures Resolving complex server issues escalated by other internal department +s by administration and troubleshooting problems. Ensuring clients & partners are updated on current status of issues Implement operational procedures, tools and best practice as defined i +n corporate business plan Ensure that knowledge is retained through documentation of processes a +nd procedures and implementation of server changes. Updating and maintaining our Knowledge base software. Documenting troubleshooting carried out Ensure all changes are documented through the change management proces +s Execute change management tasks in line with defined processes Assist in the analysis and resolution of problems as raised by the pro +blem management functions';

Bascically nee to reduce the new lines, if it is more than 2 and replace it with just 2 new lines.

The code I tried is,  $data=~ s/\n{2,50}/\n\n/g; but it is not working.

Pls any Monks can help me out of this.

Thanks in advance.

Replies are listed 'Best First'.
Re: Clean a chunk of data
by toolic (Bishop) on May 29, 2013 at 12:33 UTC
    but it is not working
    In what way?

    I made 2 changes to your assignment to $data. I used q with parens because you have a single quote inside your string (client's), and I removed the trailing whitespace (other than \n) from all of your lines. This works for me:

    use warnings; use strict; my $data = q(3rd Line Support - Managed Services & Hosting Caerphilly, Wales - Circa 40k DOE + Excellent Company Benefits Permanent Posted: Wednesday, 29 May 2013 3rd Line Support - Managed Services & Hosting Role: Providing support to client's infrastructures and maintaining high ava +ilability through proactive measures Resolving complex server issues escalated by other internal department +s by administration and troubleshooting problems. Ensuring clients & partners are updated on current status of issues Implement operational procedures, tools and best practice as defined i +n corporate business plan Ensure that knowledge is retained through documentation of processes a +nd procedures and implementation of server changes. Updating and maintaining our Knowledge base software. Documenting troubleshooting carried out Ensure all changes are documented through the change management proces +s Execute change management tasks in line with defined processes Assist in the analysis and resolution of problems as raised by the pro +blem management functions); $data=~ s/\n{2,50}/\n\n/g; print "$data\n";
      Actually it is not assigned in the script, but the $data contains all the paragraph... I tried it again but failed. from an html page the $data get that data & we r not assigning it.

        In which case, perhaps your record separator isn't what you think it is?