Mostly what Graff was suggesting was that you should get your input from the command line parameters rather than prompt the user for them. That makes it easier to use the script in an automated context where you may wish to do several runs with different parameters perhaps. In essence it means replacing:

print "Enter the output file you would like to analyze: "; chomp (my $filename = <STDIN>); print "Enter the isotope you want to extract (ex: Am-241): "; chomp (my $iso= <STDIN>);

with something like:

# Validate parameters @ARGV == 2 or error ("Too few parameters"); $ARGV[0] =~ /[A-Z][a-z]?-\d{1,3}/ or error ("Expected an isotope first +"); -f $ARGV[1] or error ("<$ARGV[1]> is not a file"); # Extract parameters my ($iso, $filename) = @ARGV; ... sub error { my $msg = shift; print <<"USAGE"; Error: $msg. ExtractIso parses a given dibbly report file and extracts the record for a given isotope. Use as: ExtractIso <iso> <filename> <iso> is the isotope to be extracted. For example Am-214. <filename> is the filename (with path as required) of the record file. For example: Extract Am-214 dibbly.dat would extract and print the record for Am-214 from the dibbly.dat file in the current directory. USAGE exit -1; }

The error sub uses a HEREDOC to provide an error diagnostic and usage information.


DWIM is Perl's answer to Gödel

In reply to Re^3: REGEX on multiple lines by GrandFather
in thread REGEX on multiple lines by igotlongestname

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.