[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] How to match \* (MacPerl bug or my mistake)?



I have been digging through the O'Reilly book 
_Learning_Perl_.  Ran into a problem and I can't 
believe that MacPerl isn't doing it right.  

The goal is to match 0 or more / marks.  I can't
do it and I -think- I'm coding correctly.  

Here is the test script, run it and it explains the 
problems I'm seeing:

#!/usr/bin/perl -w

print "\n\n\n\nBegin test taken from answer of problem 7.1.b in
_Learning_Perl_, Schwartz and Randall (O'Reilly)";
print "\nHere are various attempts to match and substitute for the
string \\\\\\***** in the string aaaaa\\\\\\*****bbbbb.";

$a = "aaaaa\\\\\\*****bbbbb";
print "\n\n\$a:$a";
$a =~ m#(\\*\**)#;
print "\n\$a:$a is matching with m#(\\\\*\\**)#";
print "\n\$a should be:aaaaa\\\\\\*****bbbbb and that is exactly what I
got";
print "\n\$1:$1";
print "\n\$1 should be:\\\\\\****** but I got nothing.";


$a = "aaaaa\\\\\\*****bbbbb";
print "\n\n\$a:$a";
$a =~ s#(\\*\**)#c#;
print "\n\$a:$a is substituting with s#(\\\\*\\**)#c#";
print "\n\$a should be:aaaaacbbbbb but I got caaaaa\\\\\\*****bbbbb";
print "\n\$1:$1";
print "\n\$1 should be:\\\\\\****** but I got nothing.";

$a = "aaaaa\\\\\\*****bbbbb";
print "\n\n\$a:$a";
$a =~ s#(b*)#c#;
print "\n\$a:$a is substituting with s#(b*)#c#";
print "\n\$a should be:aaaaa\\\\\\*****c but I got
caaaaa\\\\\\*****bbbbb";
print "\n\$1:$1";
print "\n\$1 should be:\\\\\\****** but I got nothing.";

$a = "aaaaa\\\\\\*****bbbbb";
print "\n\$a:$a";
$a =~ s#(b+)#c#;
print "\n\$a:$a is substituting with s#(b+)#c#";
print "\n\$a should be:aaaaa\\\\\\*****c and that is exactly what I
got";
print "\n\$1:$1";
print "\n\$1 should be:bbbbb and that is exactly what I got";
print "\n\nSo it looks like I am not getting greedy match for b* and
that \\\\* does not match at all.";
print "\nLooks like a bug in my version of MacPerl (v5.1.3r2), which I
am running on a Quadra 700,";
print "\nMacOS 7.5.5 with 20 Mb Physical RAM, 30 Mb total with Virtual
Memory running.";

print "\n\nPlease let me know what I am doing wrong or that I'm not if
that is the case; thanks.";

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch