[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Read entire file?



>So I'm a c programmer, and my perl book is at the office.
>
>What is the best (fastest, clearest code) to read an entire file into a
>variable?  I want to preserve whatever line endings were in the original
>file so I don't want to read it by lines.  Right now I am reading by
>chunks because I can't seem to find a function that will return the size
>in bytes of the file on disk...
>
>Thanks,
>Jim
>
>--
>Jim Correia                                Bare Bones Software, Inc.
>correia@barebones.com                     <http://web.barebones.com>
>


  $fileSize = -s $filePath;
  open(FILEDATA, "$filePath" || die "Can't get $filePath... $^E" );
  read(FILEDATA, $data, $fileSize);
  close(FILEDATA);


__END__

David Seay
http://www.mastercall.com/g-s/




# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org