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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |