Perl – Compare Array Contents when length is identical and order matches Comparing arrays side by side. Do they match or dont they? @a=(1,0,1,0,0); @b=(0,0,1,0,0); NO! @arr1=(0,1,1,1,1,1,0,1); @arr2=(0,1,1,1,1,1,0,1); use Algorithm::Diff qw( LCS_length); my $arr_count1 = @arr1; my $arr_count2 = @arr2; if($arr_count1 != $arr_count2) { print “NOMATCH\n”; ## NO MATCH } else { $count = LCS_length […]
PERL – Bitwise OR XOR an array [perl] my @data= (“80″,”80″,”7B”,”30″,”32″,”30″,”38″,”31″,”46″,”30″,”39″); my $chk; foreach my $point(@data) { $chk = $chk^$point; ## XOR each array } $chk = hex($chk)|hex(“80”); ## OR the result value my $chk_hex=sprintf(“%x”,$chk); ## convert result to hex print “$chk = $chk_hex\n”; ## display both results side by side [/perl]
Map Hex Array to Ascii Where @values are an array of hex values my @ascii_vals = map (chr, map(hex,@values));
PHP Array An array stores multiple values in one single variable. What is an Array? A variable is a storage area holding a number or text. The problem is, a variable will hold only one value. An array is a special variable, which can store multiple values in one single variable. If you have a […]
Perl Push Array A slightly more interesting kind of variable is the array variable which is a list of scalars (ie numbers and strings). Array variables have the same format as scalar variables except that they are prefixed by an @ symbol. The statement @food = (“apples”, “pears”, “eels”); @music = (“whistle”, “flute”); assigns a […]