Monadic CSV
3 posts
• Page 1 of 1
Monadic CSV
I have a single CSV file tied & I'm going to append to it
⍴xxx←⎕CSV,⎕NNAMES
6 7
⎕nsize ¯1
530
xxx ⎕CSV ¯1
0
⎕nsize ¯1
1062
Well it appended the data, even though the number of bytes written is wrong, but
⍴ ⎕CSV ¯1
0 0
It doesn't seem to want to read anything back.
Have I mucked up the file position pointer by appending? I know we have the Record variant, but I can't see a "start reading from here" parameter. Which could be useful.
I tried untying & retying, but with a tie number I still get nothing back.
⍴xxx←⎕CSV,⎕NNAMES
6 7
⎕nsize ¯1
530
xxx ⎕CSV ¯1
0
⎕nsize ¯1
1062
Well it appended the data, even though the number of bytes written is wrong, but
⍴ ⎕CSV ¯1
0 0
It doesn't seem to want to read anything back.
Have I mucked up the file position pointer by appending? I know we have the Record variant, but I can't see a "start reading from here" parameter. Which could be useful.
I tried untying & retying, but with a tie number I still get nothing back.
- crishog
- Posts: 61
- Joined: Mon Jan 25, 2010 9:52 am
Re: Monadic CSV
Hi Chris -
⎕CSV can read from a named file or a tied native file. The reason for the latter is to enable the reading of "huge" files in sections - typically you'd invoke ⎕CSV specifying the 'Records' variant option to limit the number of records read, and repeatedly do this until no more records were read. Therefore, ⎕CSV leaves the file position set to the correct position for the next operation to continue from the next record, and starts reading from the current file position rather than the beginning of the file.
If you want to read from the beginning of the file after writing to it you need to reset the file position. Untying and retying is one way of doing that; that should have worked for you and I know of no reason why it did not - could you retry? A better way of doing it would be to use ⎕NREAD - if you read 0 bytes from position 0 the file position will be left at position 0.
⎕CSV can read from a named file or a tied native file. The reason for the latter is to enable the reading of "huge" files in sections - typically you'd invoke ⎕CSV specifying the 'Records' variant option to limit the number of records read, and repeatedly do this until no more records were read. Therefore, ⎕CSV leaves the file position set to the correct position for the next operation to continue from the next record, and starts reading from the current file position rather than the beginning of the file.
If you want to read from the beginning of the file after writing to it you need to reset the file position. Untying and retying is one way of doing that; that should have worked for you and I know of no reason why it did not - could you retry? A better way of doing it would be to use ⎕NREAD - if you read 0 bytes from position 0 the file position will be left at position 0.
-
Richard|Dyalog - Posts: 44
- Joined: Thu Oct 02, 2008 11:11 am
Re: Monadic CSV
I'll retest the untie/tie - probably something I did
I hadn't thought of using NREAD to set the file pointer (given that my untie didn't seem to make a difference) - that's brilliant
I hadn't thought of using NREAD to set the file pointer (given that my untie didn't seem to make a difference) - that's brilliant
- crishog
- Posts: 61
- Joined: Mon Jan 25, 2010 9:52 am
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group