open(F1, $ARGV[0]) || die; # open file 1open(F2, $ARGV[1]) || die; # open file 2while (my $l1 = <F1>) { # read one line from file 1 my $l2 = <F2>; # read one line from file 2 print "[file 1] $l1"; # print the file 1 line print "[file 2] $l2" if $l2; # print the file 2 line unless reaching end-of-file}close(F1); close(F2); # close--
Consider asking HOWTO questions at Stack Overflow: http://stackoverflow.com/tags/dart
There are methods for synchronous dealing with files and for scripting purposes, I would never hesitate to use them. Heck, I wouldn't even hesitate to load the whole file to memory at first.
Async is hard, let's go shopping.
Well, it doesn't necessarily have to be hard, but I won't miss this opportunity to say that dart:io looks like it's specifically made to make it as hard as possible :-)
LT
--
I am not sure what is wrong with C-like stream in the first place (i.e. we get a file handler and then we can fully control reading). It should be easy to wrap C-stream-like APIs to implement the dart:io APIs, but to do the reverse seems more difficult. I know we can achieve all C-stream functionality with dart:io if we think harder, but is the complication really necessary? The different dart:io APIs will also alienate many programmers who do text processing.
main() {var fileNames = new Options().arguments;var openFiles = fileNames.map((fileName) => new File(fileName).openSync(FileMode.READ));var buf = new List(65536);outerLoop: while (true) {for (var i = 0; i < openFiles.length; i++) {var openFile = openFiles[i];var read = openFile.readListSync(buf, 0, buf.length);if (i == 0) break outerLoop;print("[$i] $buf");}}}