I don't know how 1 while s/// is clearer than s///g.
What's worse, it does not work correctly:
my %map = (
F => "|",
S => "^",
T => "&",
R => "~",
E => "\\"
);
$_ = "\\E\\S\\";
s/\\([FSTRE])\\/$map{$1}/g;
print "s///g: [$_]\n";
$_ = "\\E\\S\\";
1 while s/\\([FSTRE])\\/$map{$1}/;
print "1 while s///: [$_]\n";
__END__
s///g: [\S\]
1 while s///: [^]
\E\S\ gets translated to \S\, as per the OP's spec, but the 1 while s/// solution then blithely goes on to translate that as well. Oops.
(Note that there's a bunch of minor mistakes in your code. The last slash in your s/// is missing and (FSTRE) should be ([FSTRE]).)
Makeshifts last the longest.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.