Sponsored Content
Top Forums Shell Programming and Scripting Cleaning up Arrays with duplicate values Post 302439803 by radoulov on Friday 23rd of July 2010 06:26:05 PM
Old 07-23-2010
Something like this:

Code:
@merge{@linecount, @hit} = (1) x @linecount + @hit;
@all_unique = sort { $a <=> $b } keys %merge;

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Concatenating arrays cell values in shell scripting

Hi All, I want to concatenate the array cell values and form a string.. Is it possible? for ex. I have an array word_array contains d u m b and after concatenating the string shld be 'dumb' thanks (2 Replies)
Discussion started by: mathur
2 Replies

2. Shell Programming and Scripting

storing values in arrays using shell

Friends, I have to execute a command and store its contents into an array using shell. this is what i have tried #!/bin/bash disk_names = ($(`iostat -xtc | egrep -v "device|nfs" | awk '{print $1}'| tr '\n' ' ' `)) But its throwing an error message as ./test-script ./test-script:... (6 Replies)
Discussion started by: achak01
6 Replies

3. Shell Programming and Scripting

Storing values in arrays using csh

I am reading a number of files but then I want to put the ranges xmin xmax ymin ymax as arrays for each file. Any idea how I can do this??? set j = 1 echo "Welcome $i times" while ( $j <= $i ) echo "$j" set fname = $fin-bst-misf.xy echo " "$fname ... (0 Replies)
Discussion started by: kristinu
0 Replies

4. Shell Programming and Scripting

Storing values in arrays

I have the following csh script which lets the use pass the following as an argument -legend=tag1/tag2/tag3/tag4/tag5/tag6/tag7 We pass a number of tags separated by '/'. I want to save the legend tags in an array and have done as below. How can I improve on this as things are getting quite... (3 Replies)
Discussion started by: kristinu
3 Replies

5. Shell Programming and Scripting

arrays and two values

I have requirement where I need to capture the highest values of items from a feed that runs for N hours. For example lets assume my data looks like this first feed ======== appples 10 oranges 20 pears 14 second feed ========== apples 5 oranges 30 pears 1 Last feed... (6 Replies)
Discussion started by: BeefStu
6 Replies

6. Shell Programming and Scripting

How do I find the sum of values from two arrays?

Hi I have redc containing the values 3, 6, 2, 8, and 1. I have work containing the values 8, 2, 11, 7, and 9. Is there a way to find the sum of redc and work? I need to compare the sum of those two arrays to something else, so is it okay to put that into my END? TY! (4 Replies)
Discussion started by: razrnaga
4 Replies

7. Shell Programming and Scripting

Using dynamic arrays to extract the values

Hi all, We have requirement to generate load timing based on subject areas HOUSEHOLD, BANKING and TRADING. These values are stored in an array SUB_ARR SUB_ARR=("HOUSEHOLD" "BANKING" "TRADING") Based on indicator files produced while processing data for each type, we need to get the stats (using... (2 Replies)
Discussion started by: sanjaydubey2006
2 Replies

8. Shell Programming and Scripting

Modifying the values of dynamically named arrays

Hi all, In ksh, I'm trying to loop through all of my arrays, named array1, array2, array3..., and update the indices. But I'm getting errors and I'm not sure how to fix them. The errors are ./parse.sh: 6+1: not found The code is: eval \${array$c}=$(eval \${array$c}+1 ) Any help... (12 Replies)
Discussion started by: nicksantos1
12 Replies

9. Shell Programming and Scripting

Compare two arrays by values [BASH]

I have 2 arrays of values for example A1 ={10 15 3 21} A2 ={10 15 3 22} I need to check which one has greater values. However: A1 ={10 15 3 21} A2 ={10 15 3 21 3} - this one would be greater. A1 ={10 15 5 21} - this one greater A2 ={10 15 3 21} Basically, I want to compare patch... (6 Replies)
Discussion started by: Jutsimitsu
6 Replies

10. Shell Programming and Scripting

Find duplicate values in specific column and delete all the duplicate values

Dear folks I have a map file of around 54K lines and some of the values in the second column have the same value and I want to find them and delete all of the same values. I looked over duplicate commands but my case is not to keep one of the duplicate values. I want to remove all of the same... (4 Replies)
Discussion started by: sajmar
4 Replies
Async::MergePoint(3pm)					User Contributed Perl Documentation				    Async::MergePoint(3pm)

NAME
"Async::MergePoint" - resynchronise diverged control flow SYNOPSIS
use Async::MergePoint; my $merge = Async::MergePoint->new( needs => [ "leaves", "water" ], ); my $water; Kettle->boil( on_boiled => sub { $water = shift; $merge->done( "water" ); } ); my $tea_leaves; Cupboard->get_tea_leaves( on_fetched => sub { $tea_leaves = shift; $merge->done( "leaves" ); } ); $merge->close( on_finished => sub { # Make tea using $water and $tea_leaves } ); DESCRIPTION
Often in program logic, multiple different steps need to be taken that are independent of each other, but their total result is needed before the next step can be taken. In synchonous code, the usual approach is to do them sequentially. An asynchronous or event-based program could do this, but if each step involves some IO idle time, better overall performance can often be gained by running the steps in parallel. A "Async::MergePoint" object can then be used to wait for all of the steps to complete, before passing the combined result of each step on to the next stage. A merge point maintains a set of outstanding operations it is waiting on; these are arbitrary string values provided at the object's construction. Each time the "done()" method is called, the named item is marked as being complete. When all of the required items are so marked, the "on_finished" continuation is invoked. For use cases where code may be split across several different lexical scopes, it may not be convenient or possible to share a lexical variable, to pass on the result of some asynchronous operation. In these cases, when an item is marked as complete a value can also be provided which contains the results of that step. The "on_finished" callback is passed a hash (in list form, rather than by reference) of the collected item values. This module was originally part of the IO::Async distribution, but was removed under the inspiration of Pedro Melo's Async::Hooks distribution, because it doesn't itself contain anything IO-specific. CONSTRUCTOR
$merge = Async::MergePoint->new( %params ) This function returns a new instance of a "Async::MergePoint" object. The %params hash takes the following keys: needs => ARRAY Optional. An array containing unique item names to wait on. The order of this array is not significant. on_finished => CODE Optional. CODE reference to the continuation for when the merge point becomes ready. If provided, will be passed to the "close" method. METHODS
$merge->close( %params ) Allows an "on_finished" continuation to be set if one was not provided to the constructor. on_finished => CODE CODE reference to the continuation for when the merge point becomes ready. The "on_finished" continuation will be called when every key in the "needs" list has been notified by the "done()" method. It will be called as $on_finished->( %items ) where the %items hash will contain the item names that were waited on, and the values passed to the "done()" method for each one. Note that this is passed as a list, not as a HASH reference. While this feature can be used to pass data from the component parts back up into the continuation, it may be more direct to use normal lexical variables instead. This method allows the continuation to be placed after the blocks of code that execute the component parts, so it reads downwards, and may make it more readable. $merge->needs( @keys ) When called on an open MergePoint (i.e. one that does not yet have an "on_finished" continuation), this method adds extra key names to the set of outstanding names. The order of this list is not significant. This method throws an exception if the MergePoint is already closed. $merge->done( $item, $value ) This method informs the merge point that the $item is now ready, and passes it a value to store, to be passed into the "on_finished" continuation. If this call gives the final remaining item being waited for, the "on_finished" continuation is called within it, and the method will not return until it has completed. EXAMPLES
Asynchronous Plugins Consider a program using "Module::Pluggable" to provide a plugin architecture to respond to events, where sometimes the response to an event may require asynchronous work. A "MergePoint" object can be used to coordinate the responses from the plugins to this event. my $merge = Async::MergePoint->new(); foreach my $plugin ( $self->plugins ) { $plugin->handle_event( "event", $merge, @args ); } $merge->close( on_finished => sub { my %results = @_; print "All plugins have recognised $event "; } ); Each plugin that wishes to handle the event can use its own package name, for example, as its unique key name for the MergePoint. A plugin handling the event synchonously could perform something such as: sub handle_event { my ( $event, $merge, @args ) = @_; .... $merge->needs( __PACKAGE__ ); $merge->done( __PACKAGE__ => $result ); } Whereas, to handle the event asynchronously the plugin can instead perform: sub handle_event { my ( $event, $merge, @args ) = @_; .... $merge->needs( __PACKAGE__ ); sometime_later( sub { $merge->done( __PACKAGE__ => $result ); } ); } AUTHOR
Paul Evans <leonerd@leonerd.org.uk> perl v5.12.3 2011-06-10 Async::MergePoint(3pm)
All times are GMT -4. The time now is 10:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy