Get your CodeRanch badge!*
The moose likes Perl and the fly likes string array comparision in perl Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Languages » Perl
Bookmark "string array comparision in perl" Watch "string array comparision in perl" New topic
Author

string array comparision in perl

anandkumar biyani
Greenhorn

Joined: Dec 06, 2011
Posts: 9
Hey can anyone help me out and tell how do we compare two arrays of string?

Thanks in advance...
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10912
    
  12

What do you mean? Compare them how? Do you want to know if they contain the same strings, the same number of strings, the same strings in the same order...

How you would do it depends on what your SPECIFIC requirements are...


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
anandkumar biyani
Greenhorn

Joined: Dec 06, 2011
Posts: 9
Hello,

Actually am getting outputs of executing two different commands as an array shown below. I want to check if all the nodes in 1st array are present in second array.

$VAR1 = [
'<3x2 IO 2>
',
'R10-IC
',
'R21-ID
',
'R00-ID
',
'R20-ID
',
'R11-ID
',
'R00-IC
',
'R01-ID
',
'R21-IC
',
'R01-IC
',
'R20-IC
',
'R11-IC
',
'R10-ID
'
];


$VAR1 = [
'
',
'LOCATION
',
'--------
',
'R00-IC
',
'R00-ID
',
'R01-IC
',
'R01-ID
',
'R10-IC
',
'R10-ID
',
'R11-IC
',
'R11-ID
',
'R20-IC
',
'R20-ID
',
'R21-IC
',
'R21-ID
',
'
',
' 12 record(s) selected.
',
'
'
];

I wanted to compare this two arrays ignoring <3x2 IO 2>, 'LOCATION, '-------- and 12 record(s) selected.

Thanks.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10912
    
  12

I would probably put each of the strings I care about from the 2nd array into a hash. Then, I'd take each string from the first array, and check to see if it is in the hash.
anandkumar biyani
Greenhorn

Joined: Dec 06, 2011
Posts: 9
Hey can you please write the code for me and post..
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10912
    
  12

anandkumar biyani wrote:Hey can you please write the code for me and post..

No, I won't.

Further, I will delete it if anyone else does. That's not what we do here.

Unless, of course, you are willing to pay. My rate is $200/hour, with a four hour minimum. You can simply make the contribution to the JavaRanch, and when the owner confirms they money, I will be glad to write your code for you.
Siitesh Hind
Ranch Hand

Joined: Sep 06, 2012
Posts: 51
@fred

There is no hash in Perl. Its just how you do the processing from the array element.

Hope this helps (both of you)
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10912
    
  12

Siitesh Hind wrote:There is no hash in Perl.

There isn't? Then what are they talking about here?

And my O'Reilly book "Learning Perl" has an entire chapter (chap 5) called "Hashes" (ok, the current version has it in Chap 6, but mine is fifteen years old...)

Heck, the article you linked to in the other Perl thread even says Perl has them:

Siitesh Hind wrote:
Lot of stuff is available on the net unless you really want to buy a book where you wont find the important things that you require.

http://www.tizag.com/perlT/perlvariables.php

Rgds,

Seetesh
Siitesh Hind
Ranch Hand

Joined: Sep 06, 2012
Posts: 51
@Fred

We both are referring to "Hash variables" in Perl.

Only issue with this is "Duplicate data entry will create a problem while fetching.

This developer can might as well use a 2 D array for putting any values including duplicates using "push" and retrieve them using a for loop.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: string array comparision in perl
 
Similar Threads
date format with MS Access database
How to convert byte array into string array?
Tech Word Game
WA #1.....word association
ResultSet to Array