in reply to esn.pl

Well, there are a number of things wrong here, so since you asked for improvements...

And of course the whole thing can be done more compactly and simply:

use English; if (@ARGV and $ARGV[0] eq "-v") { shift; # crude method for option handling (cf. Getopt::Std) print STDERR "ESN Converter v.02\n"; # report version when asked } # (otherwise, keep quiet about that) unless (@ARGV and -r $ARGV[0]) { # if no file name, go interactive print STDERR "Usage: $0 [esn_list.filename]\n"; $eof = ( $OSNAME =~ /.n.x$/ ) ? "^D" : "^Z"; $prompt = "Please enter an ESN string (or $eof to exit): "; print STDERR $prompt; } while (<>) { s/\s+//g; # start by eliminating all whitespace unless ( /^([0-9a-f]{2})([0-9a-f]{6})$/ ) { print STDERR "skipped input string $_ : not a valid ESN\n"; next; # only accept 8-digit hex strings } ($mfg,$serno) = (hex $1, hex $2); printf( "Hex: %s == Decimal: %d %d\n",$_,$mfg,$serno); } continue { print STDERR $prompt if $prompt; }
This adds the ability to accept an input file that contains one or more ESN's (one per line), since this might be more effective for some users than having to type ESNs interactively -- but interactive type-ins are still possible as well, with the ability to type in more than one ESN on a given run.

Printing prompts, version and error messages to STDERR makes it easy to redirect valid results to a file, since that might be a useful feature.

Other approaches are possible and could be better, but this seems close to your original intent.