[grand-rapids-pm-list] Perl puzzle / Meeting Friday

Brian Barto brian at bartosoft.com
Thu May 24 08:34:13 PDT 2007


Forgot what day it was. Tomorrow would be the day of the meeting :)

On Thu, 2007-05-24 at 10:48 -0400, Brian Barto wrote:
> I waited to respond since I can't make the meeting today. But since it's
> been almost 24 hours with no responses (that i've seen), I can't resist.
> 
> The quick explanation is that a hyphen can have a special meaning inside
> character class brackets. If it is placed in a position where there is a
> character before and after it, it represents a range between those two
> characters, and not interpreted literally. To have perl match a hyphen
> inside of a character class definition, the only two valid positions are
> at the beginning or at the end of the character set.
> 
> On Wed, 2007-05-23 at 10:35 -0400, Ed Eddington wrote:
> > Here's a problem that I recently ran into. See if you can find the problem with this pattern match. First correct answer gets choice of a free book at the meeting (you must explain your solution).
> > 
> > I'm upgrading our Wiki software and have been searching for bad links. My pattern match was not finding links that contained a "-" dash character. I simply moved the position of the '-' character in the list and it started working. The first test below finds the dash character as intended, the second fails to find it. WHY?
> > 
> > Also, drop me a line if you are coming to the lunch meeting Friday 11:30 at Priority Health Conf Center - I need to get a count for pizza.
> > 
> > Ed
> > 
> > 
> > #!/usr/bin/perl
> > 
> > my $sample = q| A wiki word can contain [[GoodCharacters]] in links
> > Some [[Questionable ones like spaces]],
> > or it may contain [[Bad :-( characters]] that are not allowed.
> > They may also contain the [[Dreaded - Dash]] which can be elusive.
> > |;
> > 
> > my $allowed  = 'A-Za-z0-9 ';
> > my $badchars =  '-\/()+,.=!@$%^&*;:';
> > my $badchars2 =  '\/()+-,.=!@$%^&*;:';   # SAME CHARS, ONLY MOVED THE '-'!
> > 
> > 
> > print "Test 1\n";
> > foreach (split('\n', $sample)){
> >     if (m/(\[\[[$allowed]+[$badchars])/) {
> >         print "Found bad chars in: $1\n";
> >     }
> > }
> > 
> > print "Test 2\n";
> > foreach (split('\n', $sample)){
> >     if (m/(\[\[[$allowed]+[$badchars2])/) {
> >         print "Found bad chars in: $1\n";
> >     }
> > }
> > 
> > 
> > ** ** **  PRIVILEGED AND CONFIDENTIAL  ** ** **
> > This email transmission contains privileged and confidential information intended only for the use of the individual or entity named above.  Any unauthorized review, use, disclosure or distribution is prohibited and may be a violation of law.  If you are not the intended recipient or a person responsible for delivering this message to an intended recipient, please delete the email and immediately notify the sender via the email return address or mailto:postmaster at priority-health.com.  Thank you.
> > 
> > - end -
> > 
> > _______________________________________________
> > grand-rapids-pm-list mailing list
> > grand-rapids-pm-list at pm.org
> > http://mail.pm.org/mailman/listinfo/grand-rapids-pm-list
> 
> _______________________________________________
> grand-rapids-pm-list mailing list
> grand-rapids-pm-list at pm.org
> http://mail.pm.org/mailman/listinfo/grand-rapids-pm-list



More information about the grand-rapids-pm-list mailing list