RegExs and question marks...a possible bug? 
Author Message
 RegExs and question marks...a possible bug?

Hi all,

OK, this one took me a while to figure out...consider a program that
reads markup and does things accordingly.

Let's say that I have the following:

$n = 'Where are you going<proper>henny penny?</proper>asked{*filter*}y
Locky';
$foundTag = $n =~ m/<(.+)>(.*)<\/\1>/;
$tag = $1;
$text = $2;
$n =~ s|<proper>$text</proper>|ucfirst(lc($text))|sei;
print $n;

now, the output looks like this:

Where are you going<proper>henny penny?</proper>asked{*filter*}y Locky

no difference from $n! Now, let's try this (notice that in this case, $n
doesn't have a question mark contained in it after the word penny)

$n = 'Where are you going<proper>henny penny</proper>asked{*filter*}y Locky';
$foundTag = $n =~ m/<(.+)>(.*)<\/\1>/;
$tag = $1;
$text = $2;
$n =~ s|<proper>$text</proper>|ucfirst(lc($text))|sei;
print $n;

Where are you goingHenny pennyasked{*filter*}y Locky

This is what I want...what I want to know is why the f*ck when I have a
question mark in the string, it pukes on me?!

I am aware that I could do:

$n = 'Where are you going<proper>henny penny</proper>asked{*filter*}y Locky';
$n =~ s|<proper>(.*)</proper>|ucfirst(lc($1))|sei;
print $n;

and get the desired result...still, I'd like to know why the first
example doesn't work.

Thanks to anyone who can help.

/<enneth Rose

P.S. - could this be a bug in Perl?

P.P.S. - I'm using Perl 5.005_03 on Win32 (ActiveState build)



Tue, 16 Oct 2001 03:00:00 GMT  
 RegExs and question marks...a possible bug?

[snip]

Quote:
> This is what I want...what I want to know is why the f*ck when I have a
> question mark in the string, it pukes on me?!

Did you read about ? in perlre. In regexps, a question mark is a
special character.
When you have a problem using a certain feature/function, it is best
to read some documentation about that feature/function. Makes sense?

Quote:
> P.S. - could this be a bug in Perl?

A bug is defined as any behaviour that is different from what is
mentioned in the documentation. Did you check the documentation to see
what is says?


Tue, 16 Oct 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. package/caller question and possible bug

2. Questions about resource files, popup menus, a possible Scrolled bug

3. Possible bug pl 18/19 bug in file I/O SunOS 4.1.1 SPARC

4. possible bug: what=bug in h2ph platform=solaris2.4 perlversion=5.000

5. Script stops on multiple question marks

6. HTTP Question Marks?

7. ? (question mark) not recognised.

8. Question about file marking/reading

9. Question mark in titlebar

10. Our question - Possible Legacy code question...

11. Possible timegm()bug

12. possible getpwnam() bug

 

 
Powered by phpBB® Forum Software