in reply to Proper use of //x
(To see what this does, pass it a string like (Foo := 12) + 37^2-42*bar.)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; }
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; }
|
|---|