http://qs321.pair.com?node_id=135381


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 <>;