• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

string array comparision in perl

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey can anyone help me out and tell how do we compare two arrays of string?

Thanks in advance...
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
anandkumar biyani
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey can you please write the code for me and post..
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@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
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@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.
 
It is an experimental device that will make my mind that most powerful force on earth! More powerful than this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic