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

Ed Eddington Ed.Eddington at priorityhealth.com
Wed May 23 07:35:12 PDT 2007


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 -



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