Error: variable i cannot be read at compile time
Vino
vino.bheeman at hotmail.com
Fri Jan 5 12:40:41 UTC 2018
On Friday, 5 January 2018 at 12:10:33 UTC, thedeemon wrote:
> On Friday, 5 January 2018 at 09:09:00 UTC, Vino wrote:
>> Thank you very much, can you suggest the best way around
>> this issue.
>
> What exactly are you trying to do in Master()? The code seems
> very broken. Each time you write read[i] is will call read()
> and read the whole file, you're going to read the file so many
> times in this code. I don't think that was the intent.
Hi,
Please find the full code, the below code will read a
ColRead.csv file which contains the below entry
Miller America 23
John India 42
Baker Austrilia 21
Zsuwalski Japan 45
Baker America 45
Miller India 23
import std.algorithm: countUntil, joiner, sort, uniq;
import std.container.array;
import std.csv: csvReader;
import std.stdio: File, writeln;
import std.typecons: Tuple, tuple;
auto read (){
Array!string Ucol1, Ucol2; Array!int Ucol3; int rSize;
auto file =
File("C:\\Users\\bheev1\\Desktop\\Current\\Script\\Others\\ColRead.csv", "r");
foreach (record;
file.byLineCopy.joiner("\n").csvReader!(Tuple!(string, string,
int)))
{ Ucol1.insertBack(record[0]); Ucol2.insertBack(record[1]);
Ucol3.insertBack(record[2]); rSize = record.length; }
return tuple(Ucol1, Ucol2, Ucol3, rSize);
}
void main () {
Array!int Key;
int Size = read[3];
static foreach(i; 0 .. Size) {
typeof(read()[i]) Data;
Data.insertBack(sort(read[0].dup[]).uniq);
foreach(i; read[i]) { Key.insertBack(Data[].countUntil(i)); } }
}
More information about the Digitalmars-d-learn
mailing list