Hello monks, I am trying to create a script that will compare two arrays, and only print values that match up. I've looked around for answers, but I can't seem to find anything comprehensive.

My first array is:
@ServicesOnMachine = `/sbin/chkconfig --list | awk '{print \$1}'`;
which contains:
NetworkManager acpid anacron atd auditd autofs avahi-daemon avahi-dnsconfd bluetooth capi conman cpuspeed crond cups dnsmasq dund firstboot gpm haldaemon hidd hplip httpd ip6tables iptables irda irqbalance iscsi iscsid isdn kudzu lvm2-monitor mcstrans mdmonitor mdmpd messagebus multipathd netconsole netfs netplugd network nfs nfslock nscd ntpd oddjobd pand pcscd portmap psacct rawdevices rdisc readahead_early readahead_later restorecond rpcgssd rpcidmapd rpcsvcgssd saslauthd sendmail smartd sshd svnserve syslog tcsd vboxadd vboxadd-service vboxadd-x11 vncserver wdaemon winbind wpa_supplicant xfs ypbind yum-updatesd
My 2nd array is:
@ServiceCheckList = ("spray", "echo", "daytime", "discard", "chargen", + "ttdb", "ypbind", "ypserv", "yppasswdd", "ypxfrd", "tooltalk", "rsta +td", "comsat", "talk", "uucp", "finger", "netstat", "systat", "rusers +", "walld", "rexd", "rje", "netbios", "lpd", "http", "gopher", "tcpmu +x", "news", "nntp", "snmp", "mail", "smtp", "pop2", "pop3", "sendmail +", "httpd");
I want to make it so if any values from the 1st and 2nd array match up, it will print the output... Probably something like....?
foreach (@ServiceCheckList eq @ServicesOnMachine) { print $_; }
Obviously this isn't it but I need something to print only matching values. Thanks in advance! :)

In reply to Comparing two arrays... by austin43

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.