Next Tricks of the Wizards 194

Tokenizing

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


Next Copyright © 2003 M. J. Dominus