Agreed. Although not all list assignments seem to do it, and you don;t need to be using either join or x or print?

I'm pretty sure that this is an over zealous optimisation -- reusing an existing stack frame or some such.

By tying the hash, the problem disappears.

P:\test>perl sub TIEHASH { return bless {}, 'main'; } sub STORE{ $_[0]->{$_[1]} = $_[2]; } sub FETCH{ $_[0]->{$_[1]} } sub CLEAR{ undef %{$_[0]} } tie %h, 'main'; print %h = ( 1,1,1,1); ^Z 1111

I tried using B::Concise to isolate a difference between a bizarre result and an expected one.

Normal

P:\test>perl -we"print map 1, %h = (1,1,1,1);" Name "main::h" used only once: possible typo at -e line 1. 1111 P:\test>perl -MO=Concise -we"print map 1, %h = (1,1,1,1);" Name "main::h" used only once: possible typo at -e line 1. i <@> leave[t1] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 1 -e:1) v ->3 h <@> print vK ->i 3 <0> pushmark s ->4 f <|> mapwhile(other->g)[t4] lK/1 ->h e <@> mapstart lK/2 ->f 4 <0> pushmark s ->5 - <1> null lK/1 ->5 g <$> const(SPECIAL Null)[t9] s ->f d <2> aassign[t3] lKMS ->e - <1> ex-list lKP ->a 5 <0> pushmark s ->6 6 <$> const(SPECIAL Null)[t5] s ->7 7 <$> const(SPECIAL Null)[t6] s ->8 8 <$> const(SPECIAL Null)[t7] s ->9 9 <$> const(SPECIAL Null)[t8] s ->a - <1> ex-list lK ->d a <0> pushmark s ->b c <1> rv2hv[t2] lKRM*/1 ->d b <#> gv s ->c -e syntax OK

Bizarre

P:\test>perl -we"print %h = (1,1,1,1);" Name "main::h" used only once: possible typo at -e line 1. Use of uninitialized value in print at -e line 1. 111 P:\test>perl -MO=Concise -we"print %h = (1,1,1,1);" Name "main::h" used only once: possible typo at -e line 1. e <@> leave[t1] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 1 -e:1) v ->3 d <@> print vK ->e 3 <0> pushmark s ->4 c <2> aassign[t3] lKS ->d - <1> ex-list lKP ->9 4 <0> pushmark s ->5 5 <$> const(SPECIAL Null)[t4] s ->6 6 <$> const(SPECIAL Null)[t5] s ->7 7 <$> const(SPECIAL Null)[t6] s ->8 8 <$> const(SPECIAL Null)[t7] s ->9 - <1> ex-list lK ->c 9 <0> pushmark s ->a b <1> rv2hv[t2] lKRM*/1 ->c a <#> gv s ->b -e syntax OK

The only difference I can see is entirely due to the map. Exclude that, and the rest is identical.

So, a bug? If it is, it's been arounf since at least 5.6.1!


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
Hooray!


In reply to Re: Re: Erm? Bug or not? Weird behaviour in hash / list conversion by BrowserUk
in thread Erm? Bug or not? Weird behaviour in hash / list conversion by BrowserUk

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.