advanced help
phrase:
attribute:
attribute:
attribute:
order:
per page:
clip:
action:
Results of 0 - 1 of about 0 (0.000 sec.)
CSV.apl
@author: ??????
@digest: f6a8d6f63a8079ec52ef1d6ee2662a82
@id: 10495
@mdate: 2015-07-10T18:06:01Z
@size: 2477
@type: text/html
author: ??????
content-type: text/html; charset=UTF-8
copyright: © 2015 by ??????
date: 2015-7-10
description: ??????
keywords: ??????, APL, GNU
#keywords: hasquotes (39076), withquotes (29755), inquotes (22142), alexweiner (15368), csvfile (15368), ←⍉(⍴ (15368), filecontents (11091), ⍝ (7911), ←{⊃(⎕ (7815), ⍵)⊂⍨~(⎕ (7815), ⍵)∊ (7815), ←{⍵∨≠\⍵} (7815), ⍴⍨⍴ (7815), ⊂⍨~ (7815), bookend (7815), ←⌽¨ (7815), ↓¨⌽¨ (7815), ←⍕⍉(( (7815), ⍴¨ (7684), ↓¨ (7684), seps (5627), ∇ (4714), ∆ (4593), weiner (4292), ← (3534), parsed (3117), nextfile (3060), matrix (2296), csv (1930), quotes (1919), idx (1706), sep (1453)
⍝ ⍝ Author: Alex Weiner ⍝ Date: June 27, 2015 ⍝ Copyright: Copyright (C) 2015 by Alex Weiner ⍝ License: LGPL see http://www.gnu.org/licenses/gpl-3.0.en.html ⍝ Support email: alexweiner@alexweiner.com ⍝ Portability: L3 (GNU APL) ⍝ ⍝ Purpose: ⍝ Read in a text file, with a given field separator and return a ⍝ 2D matrix of text vectors ⍝ ⍝ ⍝ Create a text matrix, with a given separator and ⍝ every element will be quoted. ⍝ ⍝ Description: ⍝ parsed_csv← ',' read∆csvfile 'name of the file' ⍝text_csv_matrix←','make∆csv matrix_parsed_csv ⍝ a matrix of text vectors ⍝ ⍝ )COPY 5 FILE_IO.apl file_matrix_ucs←{⊃(⎕ucs ⍵)⊂⍨~(⎕ucs ⍵)∊10 11} ∇parsed_row←sep read∆csv∆row string inquotes_bool←{⍵∨≠\⍵}34= string sep_bool←string= ⎕ucs sep sep_idx←sep_bool/⍳⍴sep_bool sep_in_quotes_idx← (sep_idx∊inquotes_bool/⍳⍴inquotes_bool)/⍳⍴sep_idx sep_idx_real←sep_idx~sep_idx[sep_in_quotes_idx] sep_bool_real←0⍴⍨⍴string sep_bool_real[sep_idx_real]←1 parsed_row←string⊂⍨~sep_bool_real ⍝now find the bookend quotes and drop em size_each_item← ⍴¨parsed_row quotes_expected←⌽¨1,¨⌽¨1,¨2↓¨size_each_item⍴¨0 quotes_found←parsed_row=34 ⍝34←→ '"' hasquotes_bool← ∨/¨quotes_expected∧quotes_found parsed_row[hasquotes_bool/⍳⍴hasquotes_bool]←⌽¨1↓¨⌽¨1↓¨parsed_row[hasquotes_bool/⍳⍴hasquotes_bool] parsed_row←⎕ucs¨parsed_row ∇ ∇matrix←sep read∆csvfile file matrix←⊃sep read∆csv∆row¨⊂[2] file_matrix_ucs FIO∆read_file file ∇ ∇filecontents ←sep make∆csv matrix seps←⍉(⍴matrix)⍴⊂,sep withquotes←⍉(⍴matrix)⍴⌽¨(⊂,'"'),¨⌽¨(⊂,'"'),¨matrix filecontents←⍕⍉((2 1 × ⍴withquotes)-1 0)↑(2 1 ×⍴withquotes)⍴withquotes,seps ∇ ]NEXTFILE ⍝ ⍝ EOF ⍝ ...
http://www.gnu.org/savannah-checkouts/gnu/apl/Bits_and_Pieces/CSV.apl.html - [detail] - [similar]
PREV NEXT
Powered by Hyper Estraier 1.4.13, with 213361 documents and 1081391 words.