On May 28, 2004, at 8:31 PM, Mandar Rahurkar wrote:
Hi, I am trying to remove from file : 1. all characters but any alphabet and numbers.
tr/A-Za-z0-9//cd; # should handle that
2. all trailing spaces should be made to one space.
I'm not 100% sure I understand this, but I'm guessing you want:
s/ +/ /g;
following code doesnt seem to work for objective [1] mentioned above. Can anyone please point out why ?
See inline comments below...
Thanks, Mandar --- open(fp,$file) or die "Cant open $file :$!\n"; @cont=<fp>; [EMAIL PROTECTED];
Is there a reason for this? Code not shown maybe.
for(@cont) { tr/A-Z/a-z/;
This changes all uppercase letters to their lowercase eqivalents.
s/^[a-z0-9]/ /;
This replaces one lowercase letter or digit at the beginning of the matched string with a space.
s/\s+/ /g;
This replaces a run of tabs, spaces and newlines with a single space.
}
Finally, do you really need to slurp the file? Why not process it line by line?
James
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>