Sponsored Content
Top Forums Shell Programming and Scripting How to find difference between two arrays in Perl? Post 302350356 by durden_tyler on Thursday 3rd of September 2009 02:22:29 PM
Old 09-03-2009
A bit off-topic, but it may be interesting to know that Ruby has the most intuitive solution for this problem:

Code:
$
$ ruby -e 'a1 = [1,5,15,20]; a2 = [15,1]; puts a1 - a2'
5
20
$
$ ruby -e 'puts [1,5,15,20] - [15,1]'
5
20
$

tyler_durden
 

10 More Discussions You Might Find Interesting

1. Programming

perl arrays

hello ppl, i'm coding a perl script and i have the following situation: @array1 = ("test1", "test2", "test3"); @array2 = ("something1", "something2", "something1"); $var1 = "with_one_of_the_array1_values"; $var2 = "with_one_of_the_array2_values"; what i want to do is to compare $var1... (2 Replies)
Discussion started by: crashnburn
2 Replies

2. Shell Programming and Scripting

perl functions and arrays

Hi, First I will tell my objective of this function (function one). I have a table for ex: id passwd name -- ------ ----- 1 fdhgfs werwer 2 fsdfs sdfsdf 3 sdfs sdfsdf 4 fdsfs dssdf . . . . . . The id, passwd and name are the arguments for another function say two. (1 Reply)
Discussion started by: mercuryshipzz
1 Replies

3. Shell Programming and Scripting

Perl - Compare 2 Arrays

Hi all, I have the following script where the contents of file1 and file2 would be something like this: file1: 56790,0,0,100998765 89756,0,0,100567876 867645,1,3,678777654 file2: 56790,0,0,100998765 65776,0,0,4766457890 +5896,0,0,675489876 What I then want to do is check if... (4 Replies)
Discussion started by: Donkey25
4 Replies

4. Shell Programming and Scripting

perl arrays

Hi I need some help using arrays in perl. I have an array say var and a variable var1. I want to check if the var1 is present in the array. How do I check that ? my @var = 1...10; my $var1 =5; if ( $var1 in @var ) { ....... } else { ....... } Something like above. Can some... (2 Replies)
Discussion started by: ammu
2 Replies

5. Shell Programming and Scripting

Compute difference between 2 arrays perl

Hi, I have 2 arrays. I have to compute symmetric difference! @arr=qw(19205134 18630215 18453487 18416242 18338715 18227590 17698645); @arr1=qw(18227590 18053561 17698645 16966777); #The code which i used is this! @union = @isect = @diff = (); %union = %isect = (); %count =... (3 Replies)
Discussion started by: vanitham
3 Replies

6. Shell Programming and Scripting

PHP Compare 2 Arrays find difference & case insensitive

Hi, I need an elegant solotion in php. I need to compare 2 arrays (array1 & array2), to find all instances of array 2 which is not in array1. I don't want to see any instances of array1 wich is not in array2 (here "the") Array1: This, is, the, data, of, array1 Array2: this, is, data, Of,... (2 Replies)
Discussion started by: lowmaster
2 Replies

7. Shell Programming and Scripting

Difference between 2 arrays in perl

Hi, I have 2 arrays: @a=qw(19190289 18381856 12780546 10626296 9337410 8850557 7740161 8101063); @b=qw(18309897 17612870 10626296 16871843 7740161 19947571 18062861); $len=@a; print "<br> length of array1: $len<br>"; $len1=@b; print "<br> length of array2: $len1<br>"; The output... (3 Replies)
Discussion started by: vanitham
3 Replies

8. Shell Programming and Scripting

Arrays in perl

Hi all, I have a log file which has logs. I am reading logs line by line into perl arrays. I want to print all the arrays elements starting from 8(word) to end of the line. print array......array to a new file. and I have to do it in perl as res of the program in perl. Please help me on... (9 Replies)
Discussion started by: firestar
9 Replies

9. Shell Programming and Scripting

Help with displaying difference between two arrays (Bash)

The code I have is kind of long, so I'm just posting the part I'm struggling with. I've found many examples online of comparing two arrays in Bash and printing the difference between them. I've tried them all, even mixed and matched some examples with no luck. I know this can't be as hard as I'm... (9 Replies)
Discussion started by: Azrael
9 Replies

10. Shell Programming and Scripting

Perl: find next available lowest number that is available in two arrays

Hi there. I have a number allocation problem whereby I have 2 arrays built from 2 different sources. The arrays will just contain a listed of sorted numbers @a 1 7 10 14 15 16 @b 1 7 10 11 14 15 16 (2 Replies)
Discussion started by: hcclnoodles
2 Replies
RUBY-PROF(1)						      General Commands Manual						      RUBY-PROF(1)

NAME
ruby-prof - A fast ruby profiler SYNOPSIS
ruby-prof [options] <script.rb> [ script-options ] DESCRIPTION
ruby-prof is a fast profiler for ruby. It can be used as a stand-alone program (that this man page documents) or as a ruby library. Simply run the ruby program you want to profile using ruby-prof : ruby-prof script.rb At the end of execution the time spent in each method is displayed. OPTIONS
-p, --printer=printer Select a printer: flat - Prints a flat profile as text (default). graph - Prints a graph profile as text. graph_html - Prints a graph profile as html. call_tree - format for KCacheGrind -m, --min_percent=min_percent The minimum percent a method must take before being included in output reports. This option is not supported for call tree. -f, --file=path Output results to a file instead of standard out. --mode=measure_mode Select what ruby-prof should measure process - Use process time (default). wall - Use wall time. cpu - Use the CPU clock counter (only supported on Pentium and PowerPCs). --replace-progname Replace $0 when loading the ruby source file. -h, --help Show help message. -v, --version Show version. SEE ALSO
The ruby-prof website, http://ruby-prof.rubyforge.org/ AUTHOR
ruby-prof was written by Shugo Maeda <shugo@ruby-lang.org>. This manual page was written by Arnaud Cornet <arnaud.cornet@gmail.com> for the Debian project (but may be used by others). 14 October 2006 RUBY-PROF(1)
All times are GMT -4. The time now is 06:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy