简体   繁体   中英

How to compare two fields from two arrays - Perl

I have two different arrays (@first, @second, for exemple) and I wanna compare $first[2] to $second[4]. If there is a match, then I'm gonna print some things. I'm new on Perl, and I thought this was an easy task, but I cannot figure ir out...i've tried many different thing, but my resul only compared one register on the first array to the second array.

Are the values strings or numbers?

  • Compare strings with eq
  • Compare numbers with ==

In case of doubt, probably use eq :

print "String same\n" if ($first[2] eq $second[4]);
print "Number same\n" if ($first[2] == $second[4]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM