in reply to Proper use of //x

Sometimes it's useful, sometimes it isn't. In my regex class, I have an example that is a complete tokenizer for a calculator program, in one regex. The calculator accepts integer and floating-point numerals, +, -, *, /, ^, and ** operators, = for equality, := for assignment, parentheses for operator grouping, and variable names. The tokenizer is simple and easy to read:

sub tokens { my @tokens = split m{ ( \*\* | := # ** or := operator | [-+*/^()=] # some other operator | [A-Za-z]\w+ # Identifier | \d*\.\d+(?:[Ee]\d+)? # Decimal number | \d+ # Integer ) }, shift(); return grep /\S/, @tokens; }
(To see what this does, pass it a string like (Foo := 12) + 37^2-42*bar.)

Now what would this look like without /x? It would be a lot harder to understand:

sub tokens { my @tokens = split m{(\*\*|:=|[-+*/^()=]|[A-Za-z]\w+|\d*\.\d+(?:[Ee]\d+)?|\d+)|\s ++}, shift(); return grep /\S/, @tokens; }