SPUG: Word boundry regex treated differently by 5.6 and
5.005033
Ben Burnett
benwa at ocentrix.com
Thu Apr 26 02:09:26 CDT 2001
At 05:51 PM 4/25/01 -0700, Colin Meyer wrote:
>More detail can be seen from the regex debugger:
>perl -M're debug' -le '$t = "abcdefg"; print pos $t while $t =~ m/\B\w/g'
I have to admin I haven't spent much time with the perl debugger I'll take
a closer look at this.
>It is hard for me to decide if this is a new bug or a bug fix for an old
>problem. The camel says that /g causes the regex to "start the next
>match on the same variable at a position *just past* where the last
>match stopped." The older versions of Perl seem to be looking at the
>character that the last match ended on in order to determine the border
>or non-border properties of the character at pos($t). Well, it's either
>a bug with Perl, or a bug with its documentation. In either case, a
>report should be submitted with perlbug.
I think it's probably a bug with Perl itself. I can't imagine this change
in behavior was intentional. I'll have to submit it in the morning.
>What sort of problem were you attempting to solve when you came across
>this one? ;-)
Here is an excerpt of code showing the regex hard at work in a motorcycle
rental application CGI script.
...
# we need to give this request a registration number while
we are here. this number
# will be built out of the initials of each word in the
applicants name, a unique session_key,
# the applicants state, and the first two letters of the
city that the applicant is in
my $key = time();
$key .= "-" . getppid() or $LogH->append("couldn't
getppid to add to session key");
my $request_id = $PASSED_VARS{'name'};
$request_id =~ s/\B\w//g;
$request_id =~ s/\W//g;
$request_id .= "-" . $key; # . "-";
# $request_id .= $PASSED_VARS{'state'} . "-";
# my $city_portion = $PASSED_VARS{'city'};
# $city_portion =~ m/^([\w]{2})/;
# $city_portion = $1;
# $request_id .= $city_portion ;
$request_id = uc($request_id);
...
I'll eventually work out some other form of unique id for these requests
that isn't so verbose, but I wanted it to be human readable during testing.
-Ben
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
More information about the spug-list
mailing list