--f46d0447f32cb18c2304c066a888 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Hello guys, I have a simple code, but it doesn't work and don't know why. Please see it below: Input file: 1.txt which including number and letter "o" in one line. 10o10o10 Wanted output file: 2.txt in which 10 represent 10 dots and o is replaced by letter "x". ..........x..........x..........x The perl code I wrote is below: #!/usr/bin/perl use strict; use warnings; while(<>){ chomp; if(/^10o|o10o|o10\z/){ s/10/.=85=85=85/g; } s/o/x/g; print"$_\n"; } And the output file is like ".???x.???x.???" , So patter matching doesn't work. Don't know why. Could you please give me some suggestion? Thank you so much! Xi --f46d0447f32cb18c2304c066a888--
![]() |
0 |
![]() |
Hi Xi, On Sat, 19 May 2012 12:04:16 -0500 Xi Chen <cxde515@gmail.com> wrote: > Hello guys, >=20 > I have a simple code, but it doesn't work and don't know why. Please see = it > below: >=20 > Input file: 1.txt which including number and letter "o" in one line. > 10o10o10 >=20 > Wanted output file: 2.txt in which 10 represent 10 dots and o is replaced > by letter "x". > ..........x..........x..........x > The perl code I wrote is below: >=20 > #!/usr/bin/perl > use strict; > use warnings; >=20 > while(<>){ > chomp; > if(/^10o|o10o|o10\z/){ > s/10/.=E2=80=A6=E2=80=A6=E2=80=A6/g; This contains some Unicode stuff instead of ASCII dots. If you replace it w= ith: s/10/('.' x 10)/ge; It should work. Regards, Shlomi Fish > } > s/o/x/g; > print"$_\n"; > } >=20 > And the output file is like ".???x.???x.???" , So patter matching doesn't > work. Don't know why. Could you please give me some suggestion? Thank you > so much! >=20 > Xi --=20 ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ "The Human Hacking Field Guide" - http://shlom.in/hhfg I=E2=80=99d love to change the world, but they won=E2=80=99t give me the so= urce code. =E2=80=94 Unknown Please reply to list if it's a mailing list post - http://shlom.in/reply .
![]() |
0 |
![]() |
Shlomi Fish wrote: > > On Sat, 19 May 2012 12:04:16 -0500 > Xi Chen<cxde515@gmail.com> wrote: >> >> I have a simple code, but it doesn't work and don't know why. Please see it >> below: >> >> Input file: 1.txt which including number and letter "o" in one line. >> 10o10o10 >> >> Wanted output file: 2.txt in which 10 represent 10 dots and o is replaced >> by letter "x". >> ..........x..........x..........x >> The perl code I wrote is below: >> >> #!/usr/bin/perl >> use strict; >> use warnings; >> >> while(<>){ >> chomp; >> if(/^10o|o10o|o10\z/){ >> s/10/.………/g; > > This contains some Unicode stuff instead of ASCII dots. If you examine the email closely you will see it is not Unicode: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable s/10/.=85=85=85/g; > If you replace it with: > > s/10/('.' x 10)/ge; > > It should work. Or just: s/10/........../g; 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
![]() |
0 |
![]() |