Is there a Ruby equivalent of Perl Tie::File module?
+1
A:
No.
It's easy to read a file and return the lines as an Array
, just as in Perl:
array = File.readlines("testfile")
But I don't think there's a library that makes sure all operations on array
are reflected in the original file (or is more efficient for large files than the naive approach above).
molf
2009-07-21 11:29:41
Correct answer, however it should be noted that Tie::File does a memory map of a file on disk and thus provides scalable access to huge files. This is not the same as reading the whole file into memory, which would be limited by available memory.
Svante
2009-07-21 12:01:57
@Svante, agreed; added a short remark to stress performance considerations.
molf
2009-07-21 12:29:21