in reply to Reg exprs

;-) Just that you have an answer ;-)

my $input="123+45"; for ($input) { tr/ +/+ /; $_= join "+ +", split; tr/ +/+ /; } print $input;

Now try to explain that!


s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Replies are listed 'Best First'.
Re^2: Reg exprs
by ikegami (Patriarch) on Mar 24, 2008 at 08:05 UTC
    Here's another solution:
    my $input = '123+45'; my $output = ''; for ($input) { /\G ( \+ ) /xgc && do { $output .= " $1 "; redo }; /\G ( . ) /xgcs && do { $output .= $1; redo }; } print("$output\n");

    <hint>If only Perl had a substitution operator, this parser wouldn't be needed...</hint>

Re^2: Reg exprs
by ikegami (Patriarch) on Mar 24, 2008 at 08:00 UTC
    The above assumes there's no spaces in input.
      No! It assumes there is no tab in the input. Space are preserved!

      s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
      +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e