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.


In reply to Re^2: Usage of File Handles by haukex
in thread Usage of File Handles by catfish1116

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.