开发者

Proper-case first field

My text files contains this one :

COcoNut,Other,900,21_7_2011,Coimbatore,TEINGKAAY
CotTon,Others,3500,21_7_2011,Coimbatore,PARUTTI
Maize,Others,1200,21_7_2011,Coimbatore,MAKKAACHOOLAM
Bajra,Other,1325,14_7_2011,Coimbatore,KAMBU
Jowar,Other,2750,14_7_2011,Coimbatore,CHOOLAM
Ragi,Other,910,14_7_2011,Coimbatore,KEIZHVARAKU
Coconut,Grade_I,650,12_7_2011,Coimbatore,TEINGKAAY GRADE ONNU
Copra,other,5300,7_7_2011,Coimbatore,KOPPARAI
Paddy,ADT_______36,950,15_7_2011,Madurai,NELLU ADT MUPPATTI AARU
Paddy,AST_16,950,15_7_2011,Madurai,NELLU AST PATINAARU

Here i had COcoNut, cotTon JOWar, etc. But i want to print like this Coconut, Cotton, Jowar i.e., the first letter should be uppercase rather than remaining using regu开发者_如何学Golar expression in perl and not in any packages ....

And also you have seen 'Others' , but i want only 'Other' in that text files. This also added with the above expression.

Then, this text files will read and write a same files i.e., to be overwrite in that files in perl scripts

Please any one suggest me


#!/usr/bin/perl

use strict;
use warnings;

use IO::InSitu;

my ( $in, $out ) = open_rw ( '/path/to/file' );

my $separator = ',';

while ( <$in> ) {
    my @fields = split ( $separator => $_ );

    $fields[ 0 ] = ucfirst lc $fields[ 0 ];
    $fields[ 1 ] =~ s/(?<=other)s//gi;

    print { $out } join ( $separator => @fields ) . "\n";
}


s/^([^,]*)/\u\L$1/;s/,Others,/,Other,/;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜