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; } ... }
In reply to Re: Advanced warning handling?
by ikegami
in thread Advanced warning handling?
by eff_i_g
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |