Is Perl *that* good?
Paramjit Oberoi
p_s_oberoi at hotmail.com
Wed Apr 28 00:27:42 EDT 2004
>> if myregex.match(line):
>> xyz = myregex.lastm.group('xyz')
>
> Hmm. The reason this hasn't been done is that it makes the match
> method non-reentrant. For example, suppose you call some functions in
> between the matching and use of the matched object, like this:
Another thing in perl that makes regexes convenient is the 'default'
variable $_. So, maybe the following could be done:
line_a = re.compile(...)
line_b = re.compile(...)
rx = re.context()
for rx.text in sys.stdin:
if rx(line_a).match():
total += a_function() + rx[1]
elif rx(r'^msg (?P<text>.*)$').match():
print rx['text']
elif rx(line_b).match(munge(text)):
print 'munged text matches'
// similarly rx.{search, sub, ...}
But, as Peter Hansen pointed out, maybe this is more suited to a personal
utility module... What are the considerations for whether something
should or shouldn't be in the standard library?
More information about the Python-list
mailing list