Hello, Veltro,
Nice idea with 'ord'!
I've tried your code, and it outputs:
3 4 4 4 4 19 18 22 6 13 10 19 2 8 6 18 20 16 1 10 6 19 3 2 19 20 3 18
+18 1 0
Here the newline is absent, and one extra trailing space, these are not problems I think. But some extra characters at the ending does solution wrong. ( upd.:) Here I would suggest to modify printing line to one which converts undefined array elements to zero-length string, e.g.:
print( $ar[ord $_] =~ s/.\K$/ /r );
Which outputs (with extra space and without newline):
3 4 4 4 4 19 18 22 6 13 10 19 2 8 6 18 20 16 1 10 6 19 3 2 19 20 3 18
+18 1
upd.
...or back to '//' op (to avoid uninitialized value warnings):
print( ( $ar[ord $_] // '' ) =~ s/.\K$/ /r );
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|