Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re^3: find junk file

by thomas895 (Chaplain)
on Jun 07, 2012 at 07:26 UTC ( #974893=note: print w/replies, xml ) Need Help??

in reply to Re^2: find junk file
in thread find junk file

Oh, well, in that case, it's quite simple:

use constant HIGHEST_CHAR_ON_KBD => 126, #These values may differ for +you, depending on where you bought LOWEST_CHAR_ON_KBD => 9; # your keyboard. There are so +me extra, non-keyboard chars in this range, as well. while( <FILE> ) { foreach( split("", $_) ) { if( ( ord($_) > HIGHEST_CHAR_ON_KBD ) || ( ord($_) < LOWEST_CH +AR_ON_KBD) ) { say "It's a binary file"; last; } } }

It isn't the best way of doing things, but it's a start.
Update: I completely forgot about spaces, tabs, carriage returns, and line feeds.

confess( "I offer no guarantees on my code." );

Replies are listed 'Best First'.
Re^4: find junk file
by roboticus (Chancellor) on Jun 07, 2012 at 11:08 UTC


    So a file is a text file unless someone uses a space?

        ...or a tab?

        ...or a carriage return?

        ...or a newline, escape sequence, ....?


    When your only tool is a hammer, all problems look like your thumb.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://974893]
[1nickt]: Corion I feel that way a lot when I look at the news...
[1nickt]: Brethren, I just noticed in the CPAN ticker Retry, which led me to Attempt, by Mark Fowler. Does anyone have experience with either of these utilities?
[Corion]: No. Back when I toyed with the idea, I found that writing the loop explicitly was usually less code than passing the configuration+ callback to the retrier...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (13)
As of 2017-05-24 12:30 GMT
Find Nodes?
    Voting Booth?