Why the followig code is not working.
My son, let me give you some priestly advice:
When you want to find out why something isn't working you
first have to establish for the reader what your criteria
for "working" is. In other words: what were
you expecting to happen, and what really happened.
As has been noted before and I quote from the perldoc
for reverse:
reverse LIST
In list context, returns a list value consisting of the
+ ele-
ments of LIST in the opposite order. In scalar context
+, con-
catenates the elements of LIST and returns a string val
+ue with
all characters in the opposite order.
print reverse <>; # line tac, last line f
+irst
undef $/; # for efficiency of <>
print scalar reverse <>; # character tac, last l
+ine tsrif
So with that in mind, if I run the following on-liner:
perl -e 'print scalar reverse "dog" . "\n";'
I get the following terse output:
god
Let us play... If I run the following one liner:
perl -e 'print join( ",", reverse ( split "", "dog")) . "\n";'
I am now feeding reverse an array and I can now get the
result
g,o,d
I hope this clears things up for you....
Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
-
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.