What do you call the second example? The way I see it, I only posted one.
Sorry, my wording was pretty bad. I was referring to your examples of a single reference to an ‘anonymous’ scalar and of ten references to ‘anonymous’ scalars. The first one genuinely has no extra scope, whereas the second one has the for introduce the extra scope.

But why would you do that. I can't imagine any scenario where you'd do that. Can you come up with a real world example where you need to generate more than one such reference in the same scope?
The only common use of anonymous scalars that I know is as blessees when the contents don't matter. I've occasionally used this to produce ‘poor man's mixins’:
bless [ bless \do { my $anon } => A, bless \do { my $anon } => B ] => +C;
Now package C can delegate calls to methods that should be handled by package A or B. I'm not sure if that's a good usage, though.

If there was such an case, it seems to me that having different names for different variables would be a good thing.
I agree that different names for the references is good, but avoiding introducing an extra scope requires different names for the referents. That is, I'd have to write something like
bless [ bless \my $anon_in_A => A, bless \my $anon_in_B => B ] => C
instead.

In reply to Re^6: anonymous scalar reference by JadeNB
in thread anonymous scalar reference by dharanivasan

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.