G'day jmckinzie,

Welcome to the Monastery.

"Need script help"

Yes, indeed! :-)

While I'm just guessing here, it looks like you've started with a Bourne-like shell script and attempted to convert it to Perl. Whether or not that's true, what you've posted is littered with problems.

I suggest you start by reading "perlintro -- Perl introduction for beginners". Then implement what you've learned.

The "Safety net" will highlight many issues and in most cases will tell you where they are and how to fix them. I expect the most common to be messages like:

Global symbol "$x" requires explicit package name (did you forget to d +eclare "my $x"?) at <location>

Then, you'll probably get almost as many:

Bareword "xxx" not allowed while "strict subs" in use at <location>

These probably just require quoting (see "perlop: Quote and Quote-like Operators").

When you get to the "Files and I/O" section, see how the example code differs from yours and follow the links therein for further discussion. Your posted line

open(DATA, "<$tmpfile") or die "Can't open data";

has additional problems.

DATA (beyond having global scope and all the problems associated with global variables) is actually special to Perl. It doesn't exist by default:

$ perl -E 'say for <DATA>' Name "main::DATA" used only once: possible typo at -e line 1. readline() on unopened filehandle DATA at -e line 1. $

But it will come into existence in circumstances that aren't immediately obvious (especially for those new to the language).

$ perl -E 'say for <DATA>; __END__' $

It's good that you've attempted to check I/O problems with "... or die "...";"; however, the message that will be output identifies neither the file nor the problem. Hand-crafting such checks is tedious and error-prone. Let Perl do this work for you with the autodie pragma.

Having addressed all of these basic problems, you can now start looking at issues related to logic, control flow, and so on. The main one that leaps out me is the two assignments to @eplist without any intervening use of that variable.

Throughout my response, I've used examples like:

perl -E '...'

You should note that I have the environment variable, $PERL5OPT, set to "-Mstrict -Mwarnings -Mautodie" (see "perlrun: ENVIRONMENT"). To get the same output as me, either set this variable in your environment, or write the examples like:

perl -Mstrict -Mwarnings -Mautodie -E '...'

— Ken


In reply to Re: Need script help by kcott
in thread Need script help by jmckinzie

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.