Are sure that each element in @_ is always a defined value? If you know that some elements may be undef and you expect that but can't bear the uninit warnings, just disable selected warning around the block in question. Like,
no warnings 'uninitialized'; if ($_[$i] =~ /^(.+?)\.(zip|t?gz|tar|bz2?|tbz)$/i) { ... }
If your Perl is older than 5.6, you can't use no warnings; and use warnings;, but you may consider to upgrade. If you're not able to do so, replace the no warnings line with local $^W = 0;.

However, if you do care that all elements should have defined values, than you need to test for defined-ness and skip if it fails the test.

for (my $i = 0; $i <= $#_; $i++) { next unless defined $_[$i] and $_[$i] =~ /^(.+?)\.(zip|t?gz|tar|bz2?|tbz)$/i or $_[$i] =~ .... and so on
So, if $_[$i] was undefined where $i is at somepoint of iteration, the execution would not even reach the first if.

And yes, I'd really like to know what happens after that undef $_[$x]. This is not the usual way in constructing multi-level loop. But beyond what you've shown and asked, I sort of believe that the problem lies on your program design. The first obvious indication to me is you need to check on /^(.+?)\.(zip|t?gz|tar|bz2?|tbz)$/i twice. The second is the inner loop on the same array.

Here's another hint. Working directly on elements of @_ will often give you unexpected results, since $_[$index] is a just reference to the original argument of the corresponding element.


Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!


In reply to Re: Warning gets the line number wrong? by naikonta
in thread Warning gets the line number wrong? by Cap'n Steve

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.