Sponsored Content
Full Discussion: Perl Compare 2 Arrays
Top Forums Shell Programming and Scripting Perl Compare 2 Arrays Post 302484753 by k_manimuthu on Monday 3rd of January 2011 05:01:18 AM
Old 01-03-2011
Code:
# Declare your array's
@Array1 = qw(Fa0/0 Fa0/1 Fa0/2 Fa0/3);
@Array2 = qw(Fa0/1 Fa0/2 Fa0/3 Fa0/4);
# compare array1 elements to array2 elements
foreach $key1 ( @Array1)
{
 $flag=0; # set the flage value
 foreach $key2 ( @Array2)
 {
  if ($key1 eq $key2)
  {
   $flag=1;
   next;
  }
 }
 # that considered array 1 element doesn't match array2 elements
 if ($flag == 0 ) 
 {
  print "\nValue '$key1' doesn't exist in \@Array2";
  ## Do your actions here
 }
   
}
# use the above logic and compare array2 to array1
# Your stuff's Here

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare two arrays in sh or compare two fields

I want a soultion to compare two arrays in sh with an easy way.I want a solution to synchrose users between different AIX servers where no NIS is available. All users are meant to be same on all 10 servers. So the approach is to consider first server as master user repository and whatever the users... (0 Replies)
Discussion started by: rijeshpp
0 Replies

2. 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

3. Shell Programming and Scripting

compare/match arrays

Hi there all, I am having a question. Is it posible to compare elements of 2 different arrays? For example I got Array 1 | Array 2 123_abc | 123_bcd 123_bcd | 234_bcd 234_abc | 567_abc 234_bcd | 123_abc than the match is 123_abc & 234_bcd and non of the others. So... (3 Replies)
Discussion started by: draco
3 Replies

4. Shell Programming and Scripting

Compare arrays in perl

Hello, Let's say that we have the two following arrays @array1= @array2= Is there any easy way to compare these two arrays and print the values that exist in array1 and not in array2 and the values that exist in array2 and not in array1? Regards, Chriss_58 (3 Replies)
Discussion started by: chriss_58
3 Replies

5. Shell Programming and Scripting

compare 2 arrays in perl

Hi Im supposed to compare lines in a file : KB0005 1019 T IFVATVPVI 0.691 PKC YES KB0005 1036 T YFLQTSQQL 0.785 PKC YES KB0005 1037 S FLQTSQQLK 0.585 DNAPK YES KB0005 1045 S KQLESEGRS 0.669 PKC YES KB0005 1045 S KQLESEGRS 0.880 unsp YES KB204320 1019 T IFVATVPVI 0.699 PKC YES ... (7 Replies)
Discussion started by: karla
7 Replies

6. Shell Programming and Scripting

Compare arrays (perl)

Hi, my first post here! Description of my problem: I have one txt-file with six rows and each row contains seven numbers seperated with whitespaces. I want to: Compare one array with seven numbers with each row of numbers in the txt-file. I have managed to compare one array with... (6 Replies)
Discussion started by: mjoh
6 Replies

7. Shell Programming and Scripting

perl: compare two arrays

Hi friends, I want to compare two arrays and find matched one using perl? Also, I want to delete unmatched one. Plz suggest me solution (1 Reply)
Discussion started by: Renesh
1 Replies

8. Shell Programming and Scripting

Compare two arrays

Hi, I am trying to compare two lists that are held in two variables so I believe I need to access the array elements to compare these. I am using ksh 88 and the code I have tried is below: for file in ${origfilelist} do if ]] then print -- "File ${file}... (3 Replies)
Discussion started by: frodo61
3 Replies

9. Shell Programming and Scripting

Using Diff to compare 2 arrays

I have two arrays and they look like this: array=(`cat /local/mnt/*sys/*includes|grep -v NEW`) array2=(`cat /tmp/*sys.z |grep -v NEW`) I am trying to compare them but I need to use the diff -u command. I am not sure how to do this. I cannot just do diff -u ${array} ${array2} I cannot... (4 Replies)
Discussion started by: newbie2010
4 Replies

10. UNIX for Beginners Questions & Answers

Compare bash arrays issue

Hello everyone, I need help comparing 2 arrays. the first array is static; the second array is not .. array1=( "macOS Mojave" "iTunes" ) cd /Volumes array2=( * ) # output of array2 macOS Mojave iTunes Mac me The problem occurs when I compare the arrays with the following code - ... (6 Replies)
Discussion started by: trexthurman
6 Replies
Bigarray(3o)							   OCaml library						      Bigarray(3o)

NAME
Bigarray - Large, multi-dimensional, numerical arrays. Module Module Bigarray Documentation Module Bigarray : sig end Large, multi-dimensional, numerical arrays. This module implements multi-dimensional arrays of integers and floating-point numbers, thereafter referred to as ``big arrays''. The implementation allows efficient sharing of large numerical arrays between Caml code and C or Fortran numerical libraries. Concerning the naming conventions, users of this module are encouraged to do open Bigarray in their source, then refer to array types and operations via short dot notation, e.g. Array1.t or Array2.sub . Big arrays support all the Caml ad-hoc polymorphic operations: -comparisons ( = , <> , <= , etc, as well as Pervasives.compare ); -hashing (module Hash ); -and structured input-output ( Pervasives.output_value and Pervasives.input_value , as well as the functions from the Marshal module). === Element kinds === === Big arrays can contain elements of the following kinds: - IEEE single precision (32 bits) floating-point numbers (Bigar- ray.float32_elt), - IEEE double precision (64 bits) floating-point numbers (Bigarray.float64_elt), - IEEE single precision (2 * 32 bits) floating-point complex numbers (Bigarray.complex32_elt), - IEEE double precision (2 * 64 bits) floating-point complex numbers (Bigar- ray.complex64_elt), - 8-bit integers (signed or unsigned) (Bigarray.int8_signed_elt or Bigarray.int8_unsigned_elt), - 16-bit integers (signed or unsigned) (Bigarray.int16_signed_elt or Bigarray.int16_unsigned_elt), - Caml integers (signed, 31 bits on 32-bit architectures, 63 bits on 64-bit architectures) (Bigarray.int_elt), - 32-bit signed integer (Bigarray.int32_elt), - 64-bit signed integers (Bigar- ray.int64_elt), - platform-native signed integers (32 bits on 32-bit architectures, 64 bits on 64-bit architectures) (Bigar- ray.nativeint_elt). Each element kind is represented at the type level by one of the abstract types defined below. === type float32_elt type float64_elt type complex32_elt type complex64_elt type int8_signed_elt type int8_unsigned_elt type int16_signed_elt type int16_unsigned_elt type int_elt type int32_elt type int64_elt type nativeint_elt type ('a, 'b) kind To each element kind is associated a Caml type, which is the type of Caml values that can be stored in the big array or read back from it. This type is not necessarily the same as the type of the array elements proper: for instance, a big array whose elements are of kind float32_elt contains 32-bit single precision floats, but reading or writing one of its elements from Caml uses the Caml type float , which is 64-bit double precision floats. The abstract type ('a, 'b) kind captures this association of a Caml type 'a for values read or written in the big array, and of an element kind 'b which represents the actual contents of the big array. The following predefined values of type kind list all possible associations of Caml types with element kinds: val float32 : (float, float32_elt) kind See Bigarray.char . val float64 : (float, float64_elt) kind See Bigarray.char . val complex32 : (Complex.t, complex32_elt) kind See Bigarray.char . val complex64 : (Complex.t, complex64_elt) kind See Bigarray.char . val int8_signed : (int, int8_signed_elt) kind See Bigarray.char . val int8_unsigned : (int, int8_unsigned_elt) kind See Bigarray.char . val int16_signed : (int, int16_signed_elt) kind See Bigarray.char . val int16_unsigned : (int, int16_unsigned_elt) kind See Bigarray.char . val int : (int, int_elt) kind See Bigarray.char . val int32 : (int32, int32_elt) kind See Bigarray.char . val int64 : (int64, int64_elt) kind See Bigarray.char . val nativeint : (nativeint, nativeint_elt) kind See Bigarray.char . val char : (char, int8_unsigned_elt) kind As shown by the types of the values above, big arrays of kind float32_elt and float64_elt are accessed using the Caml type float . Big arrays of complex kinds complex32_elt , complex64_elt are accessed with the Caml type Complex.t . Big arrays of integer kinds are accessed using the smallest Caml integer type large enough to represent the array elements: int for 8- and 16-bit integer bigarrays, as well as Caml-integer bigarrays; int32 for 32-bit integer bigarrays; int64 for 64-bit integer bigarrays; and nativeint for platform-native integer bigarrays. Finally, big arrays of kind int8_unsigned_elt can also be accessed as arrays of characters instead of arrays of small integers, by using the kind value char instead of int8_unsigned . === Array layouts === type c_layout See Bigarray.fortran_layout . type fortran_layout To facilitate interoperability with existing C and Fortran code, this library supports two different memory layouts for big arrays, one compatible with the C conventions, the other compatible with the Fortran conventions. In the C-style layout, array indices start at 0, and multi-dimensional arrays are laid out in row-major format. That is, for a two-dimen- sional array, all elements of row 0 are contiguous in memory, followed by all elements of row 1, etc. In other terms, the array elements at (x,y) and (x, y+1) are adjacent in memory. In the Fortran-style layout, array indices start at 1, and multi-dimensional arrays are laid out in column-major format. That is, for a two-dimensional array, all elements of column 0 are contiguous in memory, followed by all elements of column 1, etc. In other terms, the array elements at (x,y) and (x+1, y) are adjacent in memory. Each layout style is identified at the type level by the abstract types Bigarray.c_layout and fortran_layout respectively. type 'a layout The type 'a layout represents one of the two supported memory layouts: C-style if 'a is Bigarray.c_layout , Fortran-style if 'a is Bigar- ray.fortran_layout . === Supported layouts The abstract values c_layout and fortran_layout represent the two supported layouts at the level of values. === val c_layout : c_layout layout val fortran_layout : fortran_layout layout === Generic arrays (of arbitrarily many dimensions) === module Genarray : sig end === One-dimensional arrays === module Array1 : sig end One-dimensional arrays. The Array1 structure provides operations similar to those of Bigarray.Genarray , but specialized to the case of one-dimensional arrays. (The Array2 and Array3 structures below provide operations specialized for two- and three-dimensional arrays.) Statically knowing the number of dimensions of the array allows faster operations, and more precise static type-checking. === Two-dimensional arrays === module Array2 : sig end Two-dimensional arrays. The Array2 structure provides operations similar to those of Bigarray.Genarray , but specialized to the case of two-dimensional arrays. === Three-dimensional arrays === module Array3 : sig end Three-dimensional arrays. The Array3 structure provides operations similar to those of Bigarray.Genarray , but specialized to the case of three-dimensional arrays. === Coercions between generic big arrays and fixed-dimension big arrays === val genarray_of_array1 : ('a, 'b, 'c) Array1.t -> ('a, 'b, 'c) Genarray.t Return the generic big array corresponding to the given one-dimensional big array. val genarray_of_array2 : ('a, 'b, 'c) Array2.t -> ('a, 'b, 'c) Genarray.t Return the generic big array corresponding to the given two-dimensional big array. val genarray_of_array3 : ('a, 'b, 'c) Array3.t -> ('a, 'b, 'c) Genarray.t Return the generic big array corresponding to the given three-dimensional big array. val array1_of_genarray : ('a, 'b, 'c) Genarray.t -> ('a, 'b, 'c) Array1.t Return the one-dimensional big array corresponding to the given generic big array. Raise Invalid_argument if the generic big array does not have exactly one dimension. val array2_of_genarray : ('a, 'b, 'c) Genarray.t -> ('a, 'b, 'c) Array2.t Return the two-dimensional big array corresponding to the given generic big array. Raise Invalid_argument if the generic big array does not have exactly two dimensions. val array3_of_genarray : ('a, 'b, 'c) Genarray.t -> ('a, 'b, 'c) Array3.t Return the three-dimensional big array corresponding to the given generic big array. Raise Invalid_argument if the generic big array does not have exactly three dimensions. === Re-shaping big arrays === val reshape : ('a, 'b, 'c) Genarray.t -> int array -> ('a, 'b, 'c) Genarray.t reshape b [|d1;...;dN|] converts the big array b to a N -dimensional array of dimensions d1 ... dN . The returned array and the original array b share their data and have the same layout. For instance, assuming that b is a one-dimensional array of dimension 12, reshape b [|3;4|] returns a two-dimensional array b' of dimensions 3 and 4. If b has C layout, the element (x,y) of b' corresponds to the element x * 3 + y of b . If b has Fortran layout, the element (x,y) of b' corresponds to the element x + (y - 1) * 4 of b . The returned big array must have exactly the same number of elements as the original big array b . That is, the product of the dimensions of b must be equal to i1 * ... * iN . Otherwise, Invalid_argument is raised. val reshape_1 : ('a, 'b, 'c) Genarray.t -> int -> ('a, 'b, 'c) Array1.t Specialized version of Bigarray.reshape for reshaping to one-dimensional arrays. val reshape_2 : ('a, 'b, 'c) Genarray.t -> int -> int -> ('a, 'b, 'c) Array2.t Specialized version of Bigarray.reshape for reshaping to two-dimensional arrays. val reshape_3 : ('a, 'b, 'c) Genarray.t -> int -> int -> int -> ('a, 'b, 'c) Array3.t Specialized version of Bigarray.reshape for reshaping to three-dimensional arrays. OCamldoc 2012-06-26 Bigarray(3o)
All times are GMT -4. The time now is 04:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy