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!
|