Smells like homework!.
If so, please label it... and consider that if you merely obtain an answer here without taking the trouble to learn how to do so for yourself, you're wasting your time, that of those who provide the answer, and all the resources being expended to "educate" you.
<admonition> This is such a simple and basic question that that very asking implies an utter lack of effort to find the answer yourself.</admonition>
So, hints only: See Chapter 9 of ISBN 0596001320, your textbook, almost any reputable introduction to Perl, or the answers in your computer, for which try perldoc -q regex which will provide a start. (No, that's deliberately NOT a direct link to a specific answer, but a moment or two of your time will lead you there.)
| [reply] |
Hi,
please have a look at http://perldoc.perl.org/perlrequick.html
Keywords:
- "Extracting Matches"
- "Search and replace"
Also helpful on regex:
http://perldoc.perl.org/perlretut.html
http://perldoc.perl.org/perlre.html | [reply] |
my $input="123+45";
for ($input) {
tr/ +/+ /;
$_= join "+ +", split;
tr/ +/+ /;
}
print $input;
Now try to explain that!
s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
| [reply] [d/l] [select] |
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> | [reply] [d/l] |
The above assumes there's no spaces in input.
| [reply] |
| [reply] [d/l] [select] |
Can you show what you've tried so far? It would help to see where you are getting stuck.
| [reply] |