To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
The technical storage or access that is used exclusively for statistical purposes.
The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Can you let us know the difference , three of them produce the same output
Well, sure. I’ll be happy to post a full explanation at some point – perhaps if I leave it until next weekend that will give you all enough time to think about it.
But in the meantime, if you want to work it out for yourself you could try reading the documentation for ‘reverse’ (and, of course, ‘scalar’ and ‘print’).
Using single-digit numbers is a nice obfuscation. 🙂
@ll – Here’s a hint:
print scalar reverse qw(foo bar baz);
prints “zabraboof”.
perldoc -f reverse
I didn’t know reverse changed it’s return based on context. Learn something new every day.
Yeah, I agree — it makes this question/quiz not so much “how does context work” but “what does ‘reverse’ do in scalar context?”
Seems to me that there are two aspects to understanding context:
1/ What context is this expression being evaluated in?
2/ How do these operations and functions behave in this context?
And this example nicely demonstrates that even if the first part is (sometimes) obvious, the only sure way to get an answer to the second question is to look in the documentation.
The third statement prints a one-element list, which of course is the same backwards as it is forwards.
N.B. Although I understood these examples, I still feel that I have yet to internalize Perl context to the extent that it has become second nature. This shows up especially in more-complex examples than the ones you use here.