Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
P is for Practical
 
PerlMonks  

Re: Extend regex legibility within character classes

by knobunc (Pilgrim)
on Jun 11, 2001 at 21:34 UTC ( #87587=note: print w/ replies, xml ) Need Help??


in reply to Extend regex legibility within character classes

Why not interpolate the stuff into a variable? It can sometimes be a useful technique, but to my eye the following is more readable and obvious to people who follow.

my $valid_XML_BaseChars = join('', "\x{0041}-\x{005A}", # Uppercase A-Z "\x{0100}-\x{0131}", # Extended Latin A subset # Skipping ligatures 0132, 0133 "\x{0134}-\x{013E}", # Continuing Ext. Latin A # Skipping middle dots 013F, 0140 "\x{0141}-\x{0148}", # Finishing Ext. Latin A "\x{01FA}-\x{0217}", # Extended Latin B subset "\x{0250}-\x{02A8}", # IPA Extensions ); my $XML_BaseChar= qr/[$valid_xml_basechar]/o;

-ben


Comment on Re: Extend regex legibility within character classes
Download Code
Re: Re: Extend regex legibility within character classes
by John M. Dlugosz (Monsignor) on Jun 11, 2001 at 22:06 UTC
    That's what I started with, but wanted to get rid of the extra named variable. Using the @{[]} trick lets me write it in one statement.

    The extra variable would be less objectionable if I could hide the scope, but if the real one I'm declaring is also a "my", I can't put braces around the whole thing. It would take a third line, outside of the braces, first to declare it.

    —John

      my $XML_BaseChar= qr/$_/ for join "", "[", # a character class... "\x{0041}-\x{005A}", # the first range "\x{0100}-\x{0131}\x{0134}-\x{013E}\x{0141}-\x{0148}", # the next r +ange "\x{01FA}-\x{0217}\x{0250}-\x{02A8}", # etc. "]"; #here's how to close it up
              - tye (but my friends call me "Tye")

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://87587]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2014-04-18 05:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (462 votes), past polls