Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I’m afraid that I would come fairly unglued if I saw such an “economical” attempt to write an if statement in the fewest number of characters. The difference makes absolutely no difference at all to the Perl compiler, but it has the very human difference of being utterly un-maintainable.

Lets discuss your claims.
use strict; use warnings; use Data::Dumper; use B::Concise; sub mysub { my $val; $val = rand(2) > 1 ? "high" : "low"; return $val; } sub mysub2 { my $val; if(rand(2) > 1){ $val = "high"; } else{ $val = "low"; } return $val; } my $walker = B::Concise::compile('-src','-exec',*mysub{CODE}); print "now mysub\n"; $walker->(); $walker = B::Concise::compile('-src','-exec',*mysub2{CODE}); print "\n\n\n\nnow mysub2\n"; $walker->(); exit;
C:\Documents and Settings\Owner\Desktop>perl now mysub B::Concise::compile(CODE(0x82a6dc)) # 9: my $val; 1 <;> nextstate(main -8 v:*,&,$ 2 <0> padsv[$val:-8,-7] vM/LVINTRO # 10: $val = rand(2) > 1 ? "high" : "low"; 3 <;> nextstate(main -7 v:*,&,$ 4 <$> const[IV 2] s 5 <1> rand[t2] sK/1 6 <$> const[IV 1] s 7 <2> gt sK/2 8 <|> cond_expr(other->9) sK/1 9 <$> const[PV "high"] s goto a h <$> const[PV "low"] s a <0> padsv[$val:-8,-7] sRM* b <2> sassign vKS/2 # 11: return $val; c <;> nextstate(main -7 v:*,&,{,$ d <0> pushmark s e <0> padsv[$val:-8,-7] f <@> return K g <1> leavesub[1 ref] K/REFC,1 now mysub2 B::Concise::compile(CODE(0x9a1c44)) # 14: my $val; i <;> nextstate(main -6 v:*,&,$ j <0> padsv[$val:-6,-2] vM/LVINTRO # 15: if(rand(2) > 1){ k <;> nextstate(main -2 v:*,&,$ l <$> const[IV 2] s m <1> rand[t2] sK/1 n <$> const[IV 1] s o <2> gt sK/2 p <|> cond_expr(other->q) vK/1 q <$> const[PV "high"] s r <0> padsv[$val:-6,-2] sRM* s <2> sassign vKS/2 goto t y <0> enter v # 19: $val = "low"; z <;> nextstate(main -4 v:*,&,$ 10 <$> const[PV "low"] s 11 <0> padsv[$val:-6,-2] sRM* 12 <2> sassign vKS/2 13 <@> leave vKP # 21: return $val; t <;> nextstate(main -2 v:*,&,{,$ u <0> pushmark s v <0> padsv[$val:-6,-2] w <@> return K x <1> leavesub[1 ref] K/REFC,1 C:\Documents and Settings\Owner\Desktop>
Using conditional operator, the sub 17 ops long. Using if else blocks, the sub was 22 ops long. Have a nice day.

In reply to Re^2: if statement confusion by bulk88
in thread if statement confusion by Anonymous Monk

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    [LanX]: simple recursive function which goes left and right till l or r are exhausted
    LanX #solved
    [oiskuu]: I must watch Police Academy again sometime.
    [Discipulus]: thanks all
    [LanX]: ?

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (7)
    As of 2018-03-19 11:26 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (239 votes). Check out past polls.