...
...
$k=1;
my $arSZ = @tmpAR=split(/"/,$line);
for $x (0..$arSZ-1){
if ($x % 2 == 0) {
push(@modline,"$tmpAR[$x]");
} else {
my $count = $tmpAR[$x-1] =~ tr/,/,/; #try for something more correct
like... =~ m/\,/g);
$k = $k + $count;
push(@modline,"STRING.$k");
}
print @modline;
...
...
this replaces fields in quotes with STRING-field number.
________________________________
From: Rajeev Prasad <[email protected]>
To: Perl Beginners <[email protected]>
Sent: Saturday, September 3, 2011 10:34 AM
Subject: Re: parsing and adding back this string
comma is 'the' field seperator, if x=, then it is field seperator.
x=alpha OR numeric OR special character
ABC = uppercase alphabets
" = quotes clubs some fields together. so they are always balanced (in a pair).
we also have to find out position number of quote (") character.
From: Rob Dixon <[email protected]>
To: Perl Beginners <[email protected]>
Cc: Rajeev Prasad <[email protected]>
Sent: Saturday, September 3, 2011 4:13 AM
Subject: Re: parsing and adding back this string
On 02/09/2011 23:33, Rajeev Prasad wrote:
> friends,
>
> I am now trying to parse this string in this way...
>
> x= could be anything including special character
>
> string = xx:ABC,xx,x,x,x,"x,x,x",x,x,x,"x,x",x
>
> string0=ABC
> string2="x,x,x"
> string3="x,x"
> string1=xx:string0,tt,x,x,x,string2,x,x,x,string3,x
>
> final string is string1
Suppose x is a comma. How can you expect to parse
,,:ABC,,,,,,,,,,",,,,,",,,,,,,",,,",,
Rob