parsing and adding back this string

parsing and adding back this string

am 03.09.2011 00:33:08 von Rajeev Prasad

--0-2094112705-1315002788=:27193
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

friends,  =0AI am now trying to parse this string in this way...  =
=0Ax=3D could be anything including special character  =0Astring =3D xx=
:ABC,xx,x,x,x,"x,x,x",x,x,x,"x,x",x  =0Astring0=3DABC=0A string2=3D"x,x,=
x"=0Astring3=3D"x,x"=0Astring1=3Dxx:string0,tt,x,x,x,string2 ,x,x,x,string3,=
x  =0Afinal string is string1
--0-2094112705-1315002788=:27193--

Re: parsing and adding back this string

am 03.09.2011 00:54:24 von Rob Dixon

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

I'm afraid your post doesn't make very much sense to me, and doesn't
contain a question. Can you give an example showing what you want from
some real data?

Rob

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: parsing and adding back this string

am 03.09.2011 06:03:02 von Brandon McCaig

On Fri, Sep 2, 2011 at 6:54 PM, Rob Dixon wrote:
> I'm afraid your post doesn't make very much sense to me, and doesn't
> contain a question. Can you give an example showing what you want from
> some real data?

Agreed. As you describe, "x" can be anything, yet your sample is full
of x's all over the place. Such a loose definition basically makes the
format nearly impossible to parse. :P Either come up with a more
accurate definition (which still might be very difficult or near
impossible to parse if it's complex enough) or give up. :P Or pay
somebody with the expertise and experience to do it for you. This
sounds rather ambitious for the beginner's list.


--
Brandon McCaig
V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl.
Castopulence Software

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: parsing and adding back this string

am 03.09.2011 11:13:31 von Rob Dixon

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


--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: parsing and adding back this string

am 03.09.2011 17:34:16 von Rajeev Prasad

--0-1910426110-1315064056=:67528
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

  comma is 'the' field seperator, if x=3D, then it is field seperator.=
=0Ax=3Dalpha OR numeric OR special character=0AABC =3D uppercase alphabets=
=0A" =3D quotes clubs some fields together. so they are always balanced (in=
a pair).  =0Awe also have to find out position number of quote (") cha=
racter. From: Rob Dixon =0ATo: Perl Beginners nners@perl.org>=0ACc: Rajeev Prasad =0ASent: Saturday, =
September 3, 2011 4:13 AM=0ASubject: Re: parsing and adding back this strin=
g On 02/09/2011 23:33, Rajeev Prasad wrote:=0A> friends,=0A>=0A> I am =
now trying to parse this string in this way...=0A>=0A> x=3D could be anythi=
ng including special character=0A>=0A> string =3D xx:ABC,xx,x,x,x,"x,x,x",x=
,x,x,"x,x",x=0A>=0A> string0=3DABC=0A> string2=3D"x,x,x"=0A> string3=3D"x,x=
"=0A> string1=3Dxx:string0,tt,x,x,x,string2,x,x,x,string3,x=0A>=0A > final s=
tring is string1 Suppose x is a comma. How can you expect to parse=0A=
  ,,:ABC,,,,,,,,,,",,,,,",,,,,,,",,,",, Rob
--0-1910426110-1315064056=:67528--

Re: [solved] parsing and adding back this string

am 04.09.2011 00:47:42 von Rajeev Prasad

--0-2130998087-1315090062=:97785
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

....=0A... $k=3D1;=0Amy $arSZ =3D @tmpAR=3Dsplit(/"/,$line);  =A0=
=A0 for $x (0..$arSZ-1){     if ($x % 2 == 0) {     pus=
h(@modline,"$tmpAR[$x]");   =A0 } else {     my $count =3D=
$tmpAR[$x-1] =3D~ tr/,/,/;  =A0   =A0 #try for something more corr=
ect like...=A0 =3D~ m/\,/g);     $k =3D $k + $count;     pu=
sh(@modline,"STRING.$k");     } print @modline;=0A...=0A...=0A=
this replaces fields in quotes with STRING-field number. =
=0A________________________________=0AFrom: Rajeev Prasad om>=0ATo: Perl Beginners =0ASent: Saturday, September 3=
, 2011 10:34 AM=0ASubject: Re: parsing and adding back this string =A0=
=0Acomma is 'the' field seperator, if x=3D, then it is field seperator.=0Ax=
=3Dalpha OR numeric OR special character=0AABC =3D uppercase alphabets=0A" =
=3D quotes clubs some fields together. so they are always balanced (in a pa=
ir).  =0Awe also have to find out position number of quote (") characte=
r. From: Rob Dixon =0ATo: Perl Beginners @perl.org>=0ACc: Rajeev Prasad =0ASent: Saturday, Septe=
mber 3, 2011 4:13 AM=0ASubject: Re: parsing and adding back this string=0A=
=0AOn 02/09/2011 23:33, Rajeev Prasad wrote:=0A> friends,=0A>=0A> I am now =
trying to parse this string in this way...=0A>=0A> x=3D could be anything i=
ncluding special character=0A>=0A> string =3D xx:ABC,xx,x,x,x,"x,x,x",x,x,x=
,"x,x",x=0A>=0A> string0=3DABC=0A> string2=3D"x,x,x"=0A> string3=3D"x,x"=0A=
> string1=3Dxx:string0,tt,x,x,x,string2,x,x,x,string3,x=0A>=0A > final strin=
g is string1 Suppose x is a comma. How can you expect to parse =
   ,,:ABC,,,,,,,,,,",,,,,",,,,,,,",,,",, Rob
--0-2130998087-1315090062=:97785--

Re: [solved] parsing and adding back this string

am 04.09.2011 08:25:53 von Shlomi Fish

Hi Rajeev,

please acknowledge you have received and read this message.

On Sat, 3 Sep 2011 15:47:42 -0700 (PDT)
Rajeev Prasad wrote:

> ...
> ...
>=20
> $k=3D1;
> my $arSZ =3D @tmpAR=3Dsplit(/"/,$line);
>     for $x (0..$arSZ-1){
>     if ($x % 2 == 0) {
>     push(@modline,"$tmpAR[$x]");
>=20
>     } else {
>     my $count =3D $tmpAR[$x-1] =3D~ tr/,/,/;  =
      #try for something more
> correct like...  =3D~ m/\,/g); $k =3D $k + $count;
>     push(@modline,"STRING.$k");
>     }
>=20

This code exhibits a lot of the bad elements I've commented about here:

http://www.nntp.perl.org/group/perl.beginners/2011/09/msg118 526.html

Have you read that message and the
http://perl-begin.org/tutorials/bad-elements/ link? If so, why do you conti=
nue
writing such bad code?

Regards,

Shlomi Fish

> print @modline;
> ...
> ...
>=20
>=20
> this replaces fields in quotes with STRING-field number.
>=20
>=20
>=20
>=20


--=20
------------------------------------------------------------ -----
Shlomi Fish http://www.shlomifish.org/
"The Human Hacking Field Guide" - http://shlom.in/hhfg

In the Technion, there are many ways to get from one place to the other, but
they are all the same length.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: [solved] parsing and adding back this string

am 04.09.2011 13:52:14 von jwkrahn

Rajeev Prasad wrote:
>
> $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.

That rather complicated code could be replaced with:

my $k = 1;
my @tmpAR = split /"/, $line;
for ( my $x = 0; $x <= $#tmpAR; $x += 2 ) {
$k += $tmpAR[ $x ] =~ tr/,//;
push @modline, $tmpAR[ $x ], "STRING.$k";
}

print @modline;




John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: [solved] parsing and adding back this string

am 04.09.2011 17:05:52 von Rajeev Prasad

--0-1271158815-1315148752=:34427
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

Shlomi Fish, this is not complete code but part of it, '...' in top an=
d bottom denote that, strict warning etc is used. all variables etc are alr=
eady created using 'my'. i am using global variables. what should anybody n=
ame their variables, is upto them.=0Ayou seem to be someone who get arrogan=
t after learning few things. there are other people on this list more well =
known then you, they either do not help if they do not like, or some of the=
m understand things and help.=0Aif you think a code can be improved, you ca=
n learn from people like John W. Krahn, he has suggested the same. =0A=
=0A________________________________=0AFrom: Shlomi Fish ..org>=0ATo: Rajeev Prasad =0ACc: Perl Beginners ers@perl.org>=0ASent: Sunday, September 4, 2011 1:25 AM=0ASubject: Re: [sol=
ved] parsing and adding back this string Hi Rajeev, please acknow=
ledge you have received and read this message. On Sat, 3 Sep 2011 15:4=
7:42 -0700 (PDT)=0ARajeev Prasad wrote: > ...=0A>=
...=0A> =0A> $k=3D1;=0A> my $arSZ =3D @tmpAR=3Dsplit(/"/,$line);=0A> =A0=
   for $x (0..$arSZ-1){=0A>   =A0 if ($x % 2 == 0) {=0A>   =
=A0 push(@modline,"$tmpAR[$x]");=0A> =0A>   =A0 } else {=0A>   =A0 =
my $count =3D $tmpAR[$x-1] =3D~ tr/,/,/;  =A0   =A0 #try for someth=
ing more=0A> correct like...=A0 =3D~ m/\,/g); $k =3D $k + $count;=0A> =A0=
   push(@modline,"STRING.$k");=0A>   =A0 }=0A> This code exhi=
bits a lot of the bad elements I've commented about here: http://www.n=
ntp.perl.org/group/perl.beginners/2011/09/msg118526.html=0A= 0AHave you read=
that message and the=0Ahttp://perl-begin.org/tutorials/bad-elements/ link?=
If so, why do you continue=0Awriting such bad code? Regards, =A0=
   Shlomi Fish > print @modline;=0A> ...=0A> ...=0A> =0A> =0A> thi=
s replaces fields in quotes with STRING-field number.=0A> =0A> =0A> =0A> =
=0A-- =0A--------------------------------------------------------- ---=
-----=0AShlomi Fish=A0 =A0 =A0 http://www.shlomifish.org/=0A"The Human Hack=
ing Field Guide" - http://shlom.in/hhfg In the Technion, there are man=
y ways to get from one place to the other, but=0Athey are all the same leng=
th. Please reply to list if it's a mailing list post - http://shlom.in=
/reply . --=0ATo unsubscribe, e-mail: beginners-unsubscribe@perl.org=
=0AFor additional commands, e-mail: beginners-help@perl.org=0Ahttp://learn.=
perl.org/
--0-1271158815-1315148752=:34427--

Re: [solved] parsing and adding back this string

am 05.09.2011 08:24:43 von Shlomi Fish

Hi Rajeev,
On Sun, 4 Sep 2011 08:05:52 -0700 (PDT)
Rajeev Prasad wrote:

> Shlomi Fish,
>
> this is not complete code but part of it, '...' in top and bottom denote
> that, strict warning etc is used.

Well, first of all, it would be a good idea to include the complete code. Using
"..." to denote that strict/warnings/etc. are used is not a commonly-accepted
notation, and is very easy to miss.

> all variables etc are already created using
> 'my'. i am using global variables.

You shouldn't pre-declare your variables at the top. Instead declare them in
the smallest scope that they are used:

http://perl-begin.org/tutorials/bad-elements/#declaring_all_ vars_at_top

> what should anybody name their variables,
> is upto them.

Not entirely correct. There are good methods for naming variables and bad
methods. I've seen and heard of code with identifiers given in non-English
languages, there are obfuscated pieces of code where variables are given short,
meaningless names, and there are other examples. Source code is also intended
for people to read, and should be optimised for that.

> you seem to be someone who get arrogant after learning few
> things.

Why do you feel I am arrogant?

> there are other people on this list more well known then you, they
> either do not help if they do not like, or some of them understand things and
> help.

How is this related to the issue?

> if you think a code can be improved, you can learn from people like
> John W. Krahn, he has suggested the same.

What did John suggest, and what can I learn from him?

Regards,

Shlomi Fish

--
------------------------------------------------------------ -----
Shlomi Fish http://www.shlomifish.org/
"Humanity" - Parody of Modern Life - http://shlom.in/humanity

Deletionists delete Wikipedia articles that they consider lame.

Chuck Norris deletes Deletionists whom he considers lame.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/