I'd maybe buy your argument if the code was

given (1)

but I've never known perl to optimize lexicals away, even if those who always hold the same constant value. The following two optrees should be identical if perl optimized constant lexicals away:

>perl -MO=Concise -e"my $data = 1; print $data;" a <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 1 -e:1) v ->3 5 <2> sassign vKS/2 ->6 3 <$> const[IV 1] s ->4 4 <0> padsv[$data:1,2] sRM*/LVINTRO ->5 6 <;> nextstate(main 2 -e:1) v ->7 9 <@> print vK ->a 7 <0> pushmark s ->8 8 <0> padsv[$data:1,2] l ->9 <-- It uses the lexical, -e syntax OK not a constant. >perl -MO=Concise -e"print 1;" 6 <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 1 -e:1) v ->3 5 <@> print vK ->6 3 <0> pushmark s ->4 4 <$> const[IV 1] s ->5 <-- This is a constant. -e syntax OK

Perl 5.8.8

Update: Here's another example using code more similar to the OP's:

>perl -MO=Concise -e"my $data = 1; if ($data) { print 'moo' }" c <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 1 -e:1) v ->3 5 <2> sassign vKS/2 ->6 3 <$> const[IV 1] s ->4 4 <0> padsv[$data:1,4] sRM*/LVINTRO ->5 6 <;> nextstate(main 4 -e:1) v ->7 - <1> null vK/1 ->c 8 <|> and(other->9) vK/1 ->c <-- "if" not optimized away. 7 <0> padsv[$data:1,4] s ->8 <-- Lex not optimized away. - <@> scope vK ->- - <0> ex-nextstate v ->9 b <@> print vK ->c 9 <0> pushmark s ->a a <$> const[PV "moo"] s ->b -e syntax OK >perl -MO=Concise -e"if (1) { print 'moo' }" 6 <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 3 -e:1) v ->3 - <@> scope vK ->6 <-- "if" optimized away. - <0> ex-nextstate v ->3 5 <@> print vK ->6 3 <0> pushmark s ->4 4 <$> const[PV "moo"] s ->5 -e syntax OK

In reply to Re^3: Falling through Perl 5.10 switch statement by ikegami
in thread Falling through Perl 5.10 switch statement by Thilosophy

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.