473,320 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to compare array items

Hi
Help Me Please
Expand|Select|Wrap|Line Numbers
  1. #compare @a & @b elements.
  2. #if $a[x] = $b[y] then add to @neo
  3. #print sorted list of @neo elements
  4.  
  5. @a = qw(BB Ninja an FFF);
  6. @b = qw(ali reza cd an);
  7. @neo = qw();
  8. my $sza = @a;
  9. my $szb = @b;
  10.  
  11. for($j=0; $j <= $szb; $j++)
  12. {
  13.     for($i=0;$i <= $sza;$i++)
  14.     {
  15.     $c1 = $a[$j];
  16.     $c2 = $b[$i];
  17.         if($c1==$c2) 
  18.         {
  19.         unshift(@neo,$c2);
  20.         print $c1."  ==  ".$c2."\n";
  21.         }
  22.     }
  23. }
  24. print join("\n",sort @neo);
  25.  
Apr 8 '10 #1
5 2479
toolic
70 Expert
Add "use warnings;" to your code, then eliminate all the warning messages that are generated.

Then add "use strict;' and declare all variables with "my".

Read: http://www.perlmonks.org/?node_id=111088

If your code does not behave as desired, post your actual output and your expected output.

Use CODE tags around your code when you ask questions.
Apr 8 '10 #2
chaarmann
785 Expert 512MB
You forgot to tell us where your problem is.

Or did you just copy your homework assignment, which you are not allowed here? (the comment in the first lines leads to that assumption)
Apr 9 '10 #3
i want add joint elements to @neo.
and print ...
Apr 10 '10 #4
chaarmann
785 Expert 512MB
@sali444
You already did this in your code:
"unshift(@neo,$c2);" adds the element provided in $c2.
And "print join("\n",sort @neo);" already prints the whole sorted array.
Apr 11 '10 #5
numberwhun
3,509 Expert Mod 2GB
Sorry I didn't notice this thread sooner.

Please DO NOT post questions in the "Insights" forum. That is reserved solely for tutorials and articles. Please post all questions under the answers forum(s).

Regards,

Jeff
May 19 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Niels | last post by:
Hello, I'm trying to get te index of a specific text in a ComboBox. The ComboBox is filled by searching for filenames in a directory. The text of the last item selected in the ComboBox is saved in...
2
by: http://www.visual-basic-data-mining.net/forum | last post by:
Hi... Say i have this string call "data" in Form1, this string contains number "5" value.... how do i pass this string to the Form2 and compare with the combo box items... The combo box ...
4
by: Justin Emlay | last post by:
I have two lists. These can be in either table form or array. That is, my data is in a dataset which I can move to an array if need be. ListA is a master list and it contains all items. ListB...
0
by: ruthfish | last post by:
I am used to using VB6 and trying to work in VB.NET as my school have switched to it. I need to compare all the items loading into a combo box to items being read from an array from a text file...
6
by: Justin Fancy | last post by:
Hi Everyone, I'm lookin for a very confusing loop (to me), to compare two files. Here it is. I have two arrays with paths stored in both. example: /en/aviation/you.htm. I need to search array...
3
by: John | last post by:
I have two large arrays. Is there a rapid method to comaprs the two arrays and creat a third array of onlt thos items that the are in the first array but not the second array. I do it manually...
3
by: =?Utf-8?B?UmljY2FyZG8=?= | last post by:
What is the best method to compare 2 array to knw if each element is equal? Now, i have to compare the datarow.itemarray of 2 datarows wich is equals in structure. I tried to write this routine:...
17
by: spasmous | last post by:
I need a way to search through a block of memory for a char array "DA" using a pointer to a short. Ideally I would like to write something like: short *data = ... some data...; int j = 0;...
5
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi I have a Container that is an an Array List of Class Each ArrayList element can be the class or a another ArrayList of Class So there the ArrayList could look like Element 1 - Class...
4
by: toadstool | last post by:
I have an array containing the various products $inventory = array(); $inventory = "whatever1"; etc I have an array containing various values $quantity = array(100,200,300); I call in a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.