Appending data to array results in duplicate's.
    Moritz Maxeiner via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Fri Aug 25 09:59:04 PDT 2017
    
    
  
On Friday, 25 August 2017 at 16:45:16 UTC, Vino.B wrote:
> Hi,
>
>  Request your help on the below issue,
>
> Issue : While appending data to a array the data is getting 
> duplicated.
>
> Program:
> import std.file: dirEntries, isFile, SpanMode;
> import std.stdio: writeln, writefln;
> import std.algorithm: filter, map;
> import std.array: array;
> import std.typecons: tuple;
>
> string[] Subdata;
> void main ()
> {
>  auto dFiles = dirEntries("C:\\Temp\\TEAM", 
> SpanMode.shallow).filter!(a => a.isFile).map!(a => tuple(a.name 
> , a.timeCreated)).array;
>  foreach (d; dFiles)
> 	     {
> 		  Subdata ~= d[0];
> 		  Subdata ~= d[1].toSimpleString;
> 		  writeln(Subdata);
> 		  }
> }
>
> Output:
>
> ["C:\\Temp\\TEAM\\test1.pdf", "2017-Aug-24 18:23:00.8946851"]  
> - duplicate line
> ["C:\\Temp\\TEAM\\test1.pdf", "2017-Aug-24 18:23:00.8946851", 
> "C:\\Temp\\\\TEAM\\test5.xlsx", "2017-Aug-25 23:38:14.486421"]
>
> From,
> Vino.B
You are consecutively appending to an array in each loop 
iteration step, i.e. you are buffering, and you're printing the 
current state of the buffer (all previously buffered elements) in 
each loop iteration. I can't see any duplication going on, what 
exactly to you wish to accomplish?
    
    
More information about the Digitalmars-d-learn
mailing list