1.Why did this not only change it from reversing the list, but reversing the word itself?

Others have answered both your questions well, but I'm going to be a bit more verbose on this one (I recently did a bunch of messing around with reverse, so it's fresh in my mind)

reverse works on a list, and returns either a list or a scalar, depending on context. Your original (Camel) code: print (reverse (@list)); It's in a list context (checking perldoc -f print we see that print operates on a list, so that's what context you're in). (Note also that the outer ()'s are syntactic sugar, they have NOTHING to do with putting this into list context, print reverse @list works the same. See a thread where merlyn gives the quick explanation here.)

Now your modified version: print (reverse (@list) . " ") concatenates the results of reverse with a string, meaning that the reverse is used in a scalar context.

With me so far? Okay, now there are times when you WANT this kind of behavior. For example, when learning how to commify a number, you can't just say print reverse "10000000"; Because you'll get just "10000000" as output. (I.e. the reverse order of a list of one element). To see what it really looks like reversed, try print scalar reverse "10000000"; Of course, if you assign the result to a scalar variable rather than simply printing the result, it will be taken in a scalar context without the scalar.

reverse is an easily underestimated function. Many regexes and the like are much easier to do on the reverse of a string rather than the string itself.


In reply to Re: A simple by swiftone
in thread A simple, by Steampunk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.