Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: wxPerl Simulated 7 Segment LCD Display

by Athanasius (Chancellor)
on Jan 19, 2013 at 04:57 UTC ( #1014165=note: print w/replies, xml ) Need Help??


in reply to wxPerl Simulated 7 Segment LCD Display

As ww says, nicely done! A couple of minor points:

  1. In sub DrawSegment{, the line:

    elsif($segment = 6) { # Draw the 6 sided segment(6)

    is almost certainly a mistake: it sets $segment to the value 6, which is “true”, so the following else block will never be reached. Replace = with ==.

  2. A subroutine such as:

    sub GetValue{ my $return = $wxGlobals{mValue}; }

    would be better written as:

    sub GetValue{ return $wxGlobals{mValue}; }

    as the lexical variable $return serves no purpose here — it is being created and initialised only to be immediately thrown away. Likewise, this:

    sub Decode { # Table lookup for character t +o my($char) = @_; # Segment translation my $return; if(defined($ctbl{$char})) { $return = $ctbl{$char}; } else { $return = $ctbl{'='}; # Triple bar for undefined cha +racter } }

    works, but only (in a sense) by accident: the last expression evaluated will be an assignment to $return, so the value assigned will be returned by the sub. But with a small code change, this logic could easily break. Simpler, safer, and clearer:

    sub Decode # Table lookup for character t +o segment translation { my ($char) = @_; if (defined $ctbl{$char}) { return $ctbl{$char}; } return $ctbl{'='}; # Triple bar for undefined cha +racter }

    Update: ++BrowserUk for the much better version below!

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: wxPerl Simulated 7 Segment LCD Display
by BrowserUk (Pope) on Jan 19, 2013 at 05:28 UTC
    Simpler, safer, and clearer:

    Or just:

    # Table lookup for character to segment translation sub Decode { $ctbl{ $_[0] } // $ctbl{ '=' } }

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1014165]
help
Chatterbox?
[ambrus]: was this bug: https://rt.cpan. org/Public/Bug/ Display.html?id= 59814
[Corion]: ambrus: Oh - that one would be much harder to automate... The SYNOPSIS section should mostly be a runnable program IMO, but I write only small snippets in my documentation for single functions/methods, and creating the appropriate environment for ...
[Corion]: ... those in an automated fashion seems somewhat hard to me. Although it should do wonders for the test coverage ;)
[haukex]: Corion: I once wrote an automated thingy for that here
[haukex]: here's the code that uses it
[Corion]: haukex: Hmm - maybe I can reuse that. I see that it uses Pod::Parser, which I think was one of the more fragile parsers. But if I'm statically (re)generating the tests instead of doing that "live" on the client/tester machines, that's a much smaller...
[Corion]: ... problem space than trying to cater to all versions of Pod::Parser(s)

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (10)
As of 2017-02-27 12:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (385 votes). Check out past polls.