Next Tricks of the Wizards 195

Tokenizing

        sub tokens {
            split m{(
                     \*\* | :=  # ** or := operator 
                    |
                     [-+*/^()=]  # some other operator
                    |
                     [A-Za-z]\w+ # Identifier
                    |
                     \d*\.\d+(?:[Ee]\d+)?  # Decimal number
                    |
                     \d+         # Integer
                    )
                    |
                    \s+
                   }x, shift();
        }


Next Copyright © 2003 M. J. Dominus