foreach

Gather info through several foreach and then export-csv at the end of script

天大地大妈咪最大 提交于 2020-01-14 03:15:09
问题 I have a script that scans all my servers in my domains and outputs to two separate CSV files - one simple and one extensive. I write one line at the time to my csv.. This results in thousands of file-open and file-close.. I've lurked around and understand that I should first gather all the info and write it all in one sweep at the end of the script. But how do I do this with export-csv (preferably using a function)? And is there a way I can use the same function for short and long list? The

How can I reduce the time foreach take before and after multithreadedly going over the iterations?

∥☆過路亽.° 提交于 2020-01-13 14:43:51
问题 I use foreach + doParallel to apply a function to each row of a matrix multithreadedly in R. When the matrix has many rows, foreach takes a long time before and after multithreadedly going over the iterations. For example, if I run: library(foreach) library(doParallel) doWork <- function(data) { # setup parallel backend to use many processors cores=detectCores() number_of_cores_to_use = cores[1]-1 # not to overload the computer cat(paste('number_of_cores_to_use:',number_of_cores_to_use)) cl <

For Each Item in ListBox1 do something then add item to listbox2 vb

混江龙づ霸主 提交于 2020-01-13 05:36:29
问题 I made an app to convert certain numbers to other format i.e 1 = A 2 = B 3 = C 4 = D 5 = E ETC I have made that function with no problem and I have been using it for quite sometime, but now I would like to do things faster and in a batch. So it's really difficult for me to copy from a text file to my Textbox1 then press button1 then copy textbox2 to other text file. So I was thinking in loading the text file into a List Box then do a loop for each item in that list into a second list that I

ConcurrentModificationException: .add() vs .addAll()

不打扰是莪最后的温柔 提交于 2020-01-13 04:37:13
问题 Why does the following occur? Shouldn't both work? List<String> items = data; for( String id : items ) { List<String> otherItems = otherData; // 1. addAll() //Causes ConcurrentModificationException items.addAll(otherItems); // 2. .add() //Doesn't cause exceptions for( String otherId : otherItems ) { items.add(otherId); } } Is it because add() adds to the collection Items, but addAll() creates a new collection thus modifying Items to be a different instance of List? Edit items and otherItems

GetElementsByName with array like name

强颜欢笑 提交于 2020-01-13 04:12:57
问题 i often use this notation when i name my controls in order to get an array in POST or GET. <input name="color[1]" type="text" /> <input name="color[2]" type="text" /> <input name="color[3]" type="text" /> so in my scripts i can do <?php $data=$_GET["color"]; for each ($color as $key=>$value) { doSomething(); } ?> Often happens that i need to get those id back in javascript , but i cannot get them , so i often add an ID to each element in html like that <input name="color[3]" id="color_3" type

PHP - Foreach loops and ressources

和自甴很熟 提交于 2020-01-13 03:14:03
问题 I'm using a foreach loop to process a large set of items, unfortunately it's using alot of memory. (probably because It's doing a copy of the array). Apparently there is a way to save some memory with the following code: $items = &$array; Isn't it better to use for loops instead? And is there a way to destroy each item as soon as they have been processed in a foreach loop. eg. $items = &$array; foreach($items as $item) { dosomethingwithmy($item); destroy($item); } I'm just looking for the

Calling a class function in forEach: how Javascript handles “this” keyword

…衆ロ難τιáo~ 提交于 2020-01-13 03:13:15
问题 I'm new to Javascript and just want to make sure I'm understanding how it handles the this keyword, since... well, it seems like it's pretty messy. I've checked out similar questions on StackOverflow and want to make sure I'm not moving forward with the wrong idea. So I'm defining a class like so, and want to process every point received in the constructor. function Curve(ptList) { this.pts = []; if(ptList.length > 2) { // I want to call "addPoint" for every item in ptList right here } }

asyn foreach in jQuery

做~自己de王妃 提交于 2020-01-12 10:27:13
问题 What I want is to run a code in asynchronous mode to get a faster response (multi-thread). I have an array like "sources" with feeds and what I want is to get data from each one. I've thought something like this : $.each(sources, function(key, val) { JSON CALL OF EACH SOURCE } and then group all the results in an array and show them. The problem is that I want the json calls in asynchronous mode due to some of them take some time. How could I do the 'each' in async mode with jQuery ?? 回答1:

Iterating over two arrays simultaneously using for each loop in Java

拥有回忆 提交于 2020-01-12 08:04:54
问题 Student's names(String[]) and corresponding marks(int[]) are stored in different arrays. How may I iterate over both arrays together using for each loop in Java ? void list() { for(String s:studentNames) { System.out.println(s); //I want to print from marks[] alongside. } } One trivial way could be using index variable in the same loop. Is there a good way to do? 回答1: The underlying problem is actually that you should tie both of the arrays together and iterate across just one array. Here is

C# Break out of foreach loop after X number of items

送分小仙女□ 提交于 2020-01-11 17:07:09
问题 In my foreach loop I would like to stop after 50 items, how would you break out of this foreach loop when I reach the 50th item? Thanks foreach (ListViewItem lvi in listView.Items) 回答1: int processed = 0; foreach(ListViewItem lvi in listView.Items) { //do stuff if (++processed == 50) break; } or use LINQ foreach( ListViewItem lvi in listView.Items.Cast<ListViewItem>().Take(50)) { //do stuff } or just use a regular for loop (as suggested by @sgriffinusa and @Eric J.) for(int i = 0; i < 50 && i