Sponsored Content
Top Forums Shell Programming and Scripting How to find difference between two arrays in Perl? Post 302350065 by durden_tyler on Wednesday 2nd of September 2009 05:43:39 PM
Old 09-02-2009
Code:
$
$ perl -le '@x=(1,5,15,20); @y=(15,1); %y=map{$_=>1} @y;
>           @diff=grep(!defined $y{$_}, @x);
>           print foreach (@diff)'
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
Bigarray(3)							   OCaml library						       Bigarray(3)

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 OCaml 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 OCaml ad-hoc polymorphic operations: -comparisons ( = , <> , <= , etc, as well as Pervasives.compare ); -hashing (module Hash ); -and structured input-output (the functions from the Marshal module, as well as Pervasives.output_value and Pervasives.input_value ). === 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), - OCaml 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 an OCaml type, which is the type of OCaml 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 OCaml uses the OCaml type float , which is 64-bit double precision floats. The abstract type ('a, 'b) kind captures this association of an OCaml type 'a for values read or written in the big array, and of an ele- ment kind 'b which represents the actual contents of the big array. The following predefined values of type kind list all possible associ- ations of OCaml 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 OCaml type float . Big arrays of complex kinds complex32_elt , complex64_elt are accessed with the OCaml type Complex.t . Big arrays of integer kinds are accessed using the smallest OCaml integer type large enough to represent the array elements: int for 8- and 16-bit integer bigarrays, as well as OCaml-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 2014-06-09 Bigarray(3)
All times are GMT -4. The time now is 07:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy