Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: How can I tell if a string contains binary data or plain-old text?

by ambrus (Abbot)
on Oct 31, 2003 at 11:19 UTC ( [id://303529]=note: print w/replies, xml ) Need Help??


in reply to How can I tell if a string contains binary data or plain-old text?

Why does this one not work (on perl 5.8.0)? It should, I think, but -T always gives undef.

open A,"<",\$a or die 1;print +(-T(A) ? "text" : "bin"), $/;close A;'

  • Comment on Re: How can I tell if a string contains binary data or plain-old text?
  • Download Code

Replies are listed 'Best First'.
Re: Re: How can I tell if a string contains binary data or plain-old text?
by dakkar (Hermit) on Oct 31, 2003 at 14:34 UTC

    Odd, really. It works with a regular file, but not with an in-memory file... Bug?

    $ perl -e '$a="abc"x500;open A,"<",\$a;$x=-T(A); print +(defined($x)?$ +x?"text":"bin":"undef"),$/;close A' undef $ perl -e '$a="abc";open A,"<","/tmp/index.html";$x=-T(A); print +(def +ined($x)?$x?"text":"bin":"undef"),$/;close A' text
    -- 
            dakkar - Mobilis in mobile
    

    Most of my code is tested...

    Perl is strongly typed, it just has very few types (Dan)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://303529]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2024-04-23 08:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found