Monadic CSV

General APL language issues

Monadic CSV

Postby crishog on Thu Feb 22, 2018 3:25 pm

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.
crishog
 
Posts: 55
Joined: Mon Jan 25, 2010 9:52 am

Re: Monadic CSV

Postby Richard|Dyalog on Fri Feb 23, 2018 11:30 am

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.
User avatar
Richard|Dyalog
 
Posts: 41
Joined: Thu Oct 02, 2008 11:11 am

Re: Monadic CSV

Postby crishog on Fri Feb 23, 2018 11:46 am

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
crishog
 
Posts: 55
Joined: Mon Jan 25, 2010 9:52 am


Return to Language

Who is online

Users browsing this forum: No registered users and 1 guest