I have an application running under Apache/Mod-perl where a user can upload a csv file. The file gets uploaded, and sits in a perl variable, eventually to be loaded into an Oracle CLOB.
I want to detect if the file they've uploaded is binary or text only, and give the user a helpful error message. (Like, if they upload a .xls file.) Note that the file never exists on a filesystem, so I can't use any unix tricks (and I don't want to write out a temp file.)
I figure I can go character-by-character in a loop and look at the ascii values, but that seems horribly inefficient. Is there a quick regex that could do this check? I'm not worried about Unicode characters, but it'd be nice if extended ascii characters through, say, 165 (to get all the accented characters.)
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.