|There's more than one way to do things|
Re^2: Usage of File Handlesby haukex (Chancellor)
|on Feb 08, 2019 at 08:53 UTC||Need Help??|
What do you think about this?
You're of course free to write your code in any style you like, but I do have to say it's not something I would recommend for a beginner.
it does remove some illegal characters (<>|*?) from the name that obviously should not occur in a file name
Those are all perfectly valid characters in many *NIX OSes, see e.g. this. I also don't understand why some of those characters are simply removed and others cause the string to be cut off at that point.
my $M = @_ ? shift : 99999999;
This causes a somewhat arbitrary silent cutoff at this many lines. In general, in that code there are lots of errors that are silently swallowed.
In general, your use of vec for string operations is not a good idea for Unicode strings (in fact, it will become a fatal error in Perl 5.32). If you need to treat a string as a sequence of characters, you could either split //, $str or use substr, although normally regular expressions can handle many of the cases where one would need to do so in other languages.
Plus, there are lots of other stylistic choices that I would not recommend to a newcomer: Reinvented wheels (GetFileName instead of File::Basename or File::Spec, GetFileName($0) instead of $FindBin::Script, Trim instead of e.g. s/^[\0-\x20]+|[\0-\x20]+$//g), two-argument instead of three-argument open, uppercase variable names for non-constant variables, obfuscation by using single-letter variable names and packing function bodies on one line, unused variables...
Sorry for the long critique, but as I said this is in the context of giving code to an apparent beginner.