in reply to Advanced warning handling?
You can disable warnings at the file/function/block level:
{ no warnings 'substr'; ... use substr here ... }
In the above snippet, substr will then return the empty string ("") without giving a warning when the start position is beyond the end of the string.
Another way is to check the length of the string on which substr is called:
my $substr; if (length($_) >= 4) { $substr = substr($_, 4, 3); } else { $substr = ''; }
In your case, it looks like you'd need
orsub find_process { ... if (length($file) < $x) { warn("Skipping file $file\n"); return; } ... substr($file, $x, ...) ... ... }
sub find_process { no warnings 'substr'; ... my $part = substr($file, $x, ...); if (not length $part) { warn("Skipping file $file\n"); return; } ... }
|
|---|