#!/usr/bin/perl -w use strict; { my $v = 1; sub mk_view_v { $v; ## <<< this is an error sub { $v }; #<<<this is a no op ?? #anon sub declaration that if called #would return $v ## but if $v is 1; then mk_view_v() returns 1; ## well maybe not, maybe this is supposed to ## return a ref to the anon sub{}? ## this still looks strange to me # weird } } print "(", mk_view_v()->(), ")\n"; # very strange print statement
prints (1), as one would expect.

I would like someone to walk me thru how
mk_view_v()->() generates the expected "1"!!!

I find the above code bizarre.
What this ->() is supposed to call the anon sub within mk_view_v()?


In reply to Re: Vexing views of variables by Marshall
in thread Vexing views of variables by JadeNB

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.