No, the caret only negates the character set if it appears immediately after the left square bracket. Outside square brackets, it matches the beginning of the string or immediately after a newline. Also: the -~ sequence inside square brackets means 'any character between space and tilde, inclusive.'
So in words, the regular expression specifies 'all characters in the first 4096 (or end-of-file, whichever comes first) are "\r", "\n", "\t", or characters in the range space to tilde, inclusive, in your machine's native encoding'.
Off-topic comments:
- The -T operator will tell you if your file is ASCII/UTF-8. Just say return -T $_[0];.
- The special file handle _ (i.e. underscore) means "whatever file was last tested" under any recent Perl, and can be faster because it makes use of the same stat() structure.
- The three-argument form of open() is preferred because it handles file names with strange characters better. In your case it would be open FH, "<", $_[0]
- You should probably ensure that your open() succeeded. Something like open FH, "<", $_[0] or die "Failed to open $_[0]: $!"; is the usual idiom.
- People usually use lexical file handles rather than bareword file handles these days because they get closed automatically when they go out of scope (say, if you throw an unexpected exception). In your code that would look like open my $fh, "<", $_[0] ....
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.