Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: read()

by archen (Pilgrim)
on Dec 31, 2001 at 20:24 UTC ( [id://135381]=note: print w/replies, xml ) Need Help??


in reply to read()

What you say is all true when dealing with text files, but when it comes to dealing with non text files (like an mp3, or jpeg), read() is probably going to be your only solution since you really can't read those types of files line by line, and who knows what you'll get in an array. The usefulness of read is best understood when you understand it's compliment function seek() (well to me anyway). With these two functions you can jump around a file and read various amounts of data, without worrying about hitting an unexpected \n.

Replies are listed 'Best First'.
Re^2: read()
by Anonymous Monk on Jun 08, 2007 at 03:10 UTC
    Why can't you `my @data = <FILEHANDLE>;` for binary data? It won't exactly be logically split, but `my $r = join '', @data` works perfectly fine.... Of course, I wouldn't want a huge file in memory...
      This way you effectively pwn all of the chr(10) in your binary file... which is bad. The better "slurping" solution is to undef$/ and then using <>;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-19 22:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found