undef is a function that sets a variable to undefined as already pointed out by DragonChild. What you are after is defined which tests to see if a variable is defined so the code you want is:

if (! defined $job) {#passes this print "Job file not found! Check directory!\n";exit; }

However there is another subtle thing going on here that you should be aware of. You declare my $file outside a for loop which uses $file as the loop variable. Take particular note that the contents of $file are only valid inside the loop and that $file is an alias to the items in @files that the loop iterates over. This is not causing a problem in the code you show, but is important to remember. Especially because when you change the contents of a loop variable you are actually changing element of the list that the loop variable is currently aliased to. In you code that means that changing the contents of $file inside the loop changes the contents of an element of @files.


DWIM is Perl's answer to Gödel

In reply to Re: foreach not a global variable? by GrandFather
in thread foreach not a global variable? by jriggs420

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.