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

No Subject



I wrote:
}remove-thiis-freytag@remove.thiis.freytag.org.ethz.ch writes:
}
}}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#(\\*\**)#;
}
}Old shell programmer's lore:
}
}Try $a =~ m#(\\\\*\**)#
}
}Notice that you had to do just this below to get what you wanted printed out.  }I'm not exactly sure why you need to do this in the regexp, but I'm sure the }Camel will enlighten.
 ^^^^^^^^^^^^^^^^^^^^

Or maybe just actually thinking clearly about it will.  This "fails" (does what you asked, not what you expected) for the same reason your b* failed.  \\* matches 0 or more backslashes, so it matches the null at beginning of the line.  My change asks it to match \\* == \+, so of course it works.  That's what I get for drawing on crufty old lore rather than actually thinking about it.


---
Paul J. Schinder
NASA Goddard Space Flight Center
Code 693, Greenbelt, MD 20771
schinder@leprss.gsfc.nasa.gov



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