Mandar Rahurkar wrote:
> 
> Hi,

Hello,

>   I am trying to remove from file :
>        1. all characters but any alphabet and numbers (i.e., file shd not contain 
> anything
>           but "alphabets and numbers" that means NO punctuation etc...

Do you consider these
"ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ" to be
"alphabet" or just A-Za-z?

>        2. all trailing spaces should be made to one space.
> 
>   following code doesnt seem to work for objective [1] mentioned above.
> Can anyone please point whats wrong with the
> second line and what changes should I make ?
> 
> ---
> open(fp,$file) or die "Cant open $file :$!\n";
> @cont=<fp>;
> 
> for(@cont) {
>  tr/A-Z/a-z/;             # converts all uppercase to lowercase

If you want alphabetic characters other than A-Za-z use:

$_ = lc;

>  s/^[a-z0-9]+/ /;         # substitute all non alphabets and numbers by space
>  s/\s+/ /g;               # removes trailing spaces

The first substitution should have been s/[^a-z0-9]+/ /g and the second
substitution isn't required at all or you could have done it like this:

tr/a-z0-9/ /cs;

Or if you are using alphabetic characters other than A-Za-z use:

s/[^[:alnum:]]+/ /g;

> }


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to