As an ad-hoc method, it's been common in some perl apps I use to maintain an ever-larger list of extensions (.c, .cpp, .h, .pl, ...) to recognize if a file is source code. I can think of a number of problems with this approach:
1) All files have to have an extension. It's not uncommon for people to save scripts and makefiles without one.
2) There's an implicit assumption that there is a one-to-one mapping between each unique extension and the kind of content it should have.
3) You have to continually maintain a list of these extensions.
There's got to be a better way. From within *nix I might often do something like this
$ file -s some_file.c
and then see:
some_file.c: ASCII C program text
This brings me to some more questions:
Is there a nice tidy perl module to accomplish this effect? If not, how best to implement it?
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.