Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: What makes good Perl code?

by RedElk (Hermit)
on Aug 16, 2011 at 04:16 UTC ( #920406=note: print w/ replies, xml ) Need Help??


in reply to What makes good Perl code?

Here's a snippet of how I would approach your example in my attempt at "good code". Just another opinion, mind you.

#!/usr/bin/perl use strict; use warnings; my $voltage; my $current; my $resistance; print "I will calculate whatever you specify according to Ohm's law. What shall I calculate? \n"; menu(); sub menu() { print "\n"; print <<EOF; Press 1 for voltage. Press 2 for current. Press 3 for resistance. Press x to Exit. EOF my $selection = <STDIN>; chomp $selection; if ($selection == 1) {voltage();} elsif ($selection == 2) {current();} elsif ($selection == 3) {resistance();} elsif ($selection =~ /x,X/ {all_done();} else {print "\nSorry, that isn't on the menu. Try again!\n";} menu(); }


Comment on Re: What makes good Perl code?
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://920406]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2014-09-17 18:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (94 votes), past polls