For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > June 2005 > regarding problem with $1 in regexec









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author regarding problem with $1 in regexec
Nischi

2005-06-06, 8:55 am

Hello
i am having something like this ...

$b = "\xa0\xa0\xa0\x{100}" =~ /(\xa0+)/;
$b =~ \(\xa0+)\;
print "Valid" if ($1 eq "\xa0\xa0\xa0";
print " $b $1";

Here according to the regular expression the $1 should contain the matching string. so according $1 should have \xa0\xa0\xa0. This is happening in ASCII platform but it is not working in the EBCIDIC.

as x{100} is 2 byte character, \xa0 will also get converted to double byte which is valid. The strange thing is in $1 \xa0 is 4 bytes.

Why is that $1 is containing 4 bytes, why data is not correct.

PS: all these is happening only in EBCIDIC platform. in ASCII it is fine.





Failure is the step for success. If you know you are failed it will be easy to climb step.

---------------------------------
Too much spam in your inbox? Yahoo! Mail gives you the best spam protection for FREE!
http://in.mail.yahoo.com
Offer Kaye

2005-06-06, 3:56 pm

On 6/6/05, Nischi wrote:
> Hello
> i am having something like this ...
>=20
> $b =3D "\xa0\xa0\xa0\x{100}" =3D~ /(\xa0+)/;


Try not to use "$b" (or "$a") as variable names. "$a" and "$b" are the
special Perl sort variables and using them can cause strange bugs, for
example because even under "use strict" you can use "$b" without
declaring it.

> $b =3D~ \(\xa0+)\;


What is this line supposed to do? This does not compile...

> print "Valid" if ($1 eq "\xa0\xa0\xa0";


You are missing a ")" before the ";" at the end. Again, this is a
compile-time error.

> print " $b $1";
>=20
> Here according to the regular expression the $1 should contain the matchi=

ng string. so=20
> according $1 should have \xa0\xa0\xa0. This is happening in ASCII platfor=

m but it is not=20
> working in the EBCIDIC.
>=20
> as x{100} is 2 byte character, \xa0 will also get converted to double byt=

e which is valid.=20
> The strange thing is in $1 \xa0 is 4 bytes.
>=20
> Why is that $1 is containing 4 bytes, why data is not correct.
>=20
> PS: all these is happening only in EBCIDIC platform. in ASCII it is fine.
>=20


As I don't have access to an EBCIDIC platform, I can't check this.
However this should work:
use strict;
use warnings;
my $bb =3D "\xa0\xa0\xa0\x{100}" =3D~ /(\xa0+)/;
print "Valid\n" if ($1 eq "\xa0\xa0\xa0");
print "$bb $1\n";

HTH,
--=20
Offer Kaye
Offer Kaye

2005-06-06, 3:56 pm

On 6/6/05, Nischi wrote:
> This works in ASCII but my question is why is it not working in EBCIDIC. =

why
> $1 is not having \xa0\xa0\xa0.=20


As I said, I don't know. I don't have access to such a system. (It's
called EBCDIC, by the way - no "I" between the "C" and "D")

Maybe it's your Perl version. What is the output of "perl -V"?

Try reading "perldoc perlebcdic"
http://perldoc.perl.org/perlebcdic.html

HTH,
--=20
Offer Kaye
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com