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.


In reply to Re: esn.pl by graff
in thread esn.pl by defyance

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.