#scalar versus array context with reverse. # see http://prometheus.frii.com/%7Egnat/yapc/2000-stages/slide16.html # for where I began playing with this idea... use warnings; use strict; #scalar context, because there's a scalar on the left. my $reverse_gnat = reverse("gnat","bang"); print "1:"; print $reverse_gnat; #gnabtang print "\n"; my @reverse_gnat = reverse("gnat","bang"); print "2:"; #list context, because there's an array on the left. print @reverse_gnat; #banggnat print "\n"; print "3:"; #scalar context (because of the dot operator, I guess) print @reverse_gnat . "\n"; #2, the number of elements in the array # Commas and dots in print statements *ain't* the same... print "4:"; #list context, I guess that's the default for print. print reverse ("gnat", "bang", "\n"); #newline, then bang gnat print "\n"; # leave out the parenthesis, gnatbang\n is the only item in the list # so the effect is nothing happens print "5:"; print reverse "gnat" . "bang" . "\n"; #gnatbang print "6:"; #reverse forced into scalar context by the dot operator print reverse ("gnat") . "bang" . "\n"; #tangbang #few more examples for review. print "7:"; print reverse ("gnat") . "\n"; #tang print "8:"; print reverse "gnat" . "\n"; #gnat print "9:"; print reverse "gnat" , "\n"; #newline, then gnat

In reply to Yet another List Versus Scalar Context Meditation by tphyahoo

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.