in reply to Code Optimization v5.8.1
In my opinion (and all things are always subject to debate):
- You use last and other tools to exit loops when your loop structure could be made simpler to eliminate this hopping around. Code feels a bit goto-ish. Consider subroutines if you want extra clarity.
- Need to use 'my' to declare variables with scope rather than globally. Definitely enable 'use strict' and 'use warnings'. There are numerous reasons for this, which the books can explain in great detail.
- Program should probably process STDIN and output to STDOUT given the problem description, rather than being an interactive tool
- Stylistic, but no need to single quote items on the left side of '=>'
- If you want to clear a variable, use 'undef $var' instead of sending it the size of an empty array with '$var=()'. If you write good code, you'll rarely need to clear a variable, scoping means you don't need globals. Globals are usually a sign of a design flaw.
- Check for exit should probably read /yes|y/i instead of using what looks to be character classes... again, pick up Learning Perl or Programming Perl -- preferably both, as they cover this in depth
- No reason to assign a string to $final if you can just print a message...again, this is a sign your loop logic needs to be refactored
These are just a bunch of random comments, but you were asking for them, so I thought I would share. As you grow as a Perl programmer you will learn new tweaks and stuff, and your code will grow more elegant and easy to understand. Enjoy the process, as Perl is a really fun language and allows for some neat constructs. Don't be worried that people are pointing out ways you can improve, this monastery is an incredible resource. Most of all, realize Perl is fun!