http://www.perlmonks.org?node_id=920406


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(); }