How to get an unique element from two arrays in Perl -
i have tried list of unique elements in first array. (aka: elements in first array not in second array.) script returns number of unique elements not info in each element.
as newbie perl, know there many nuances language. have not seen how getting number instead of list of elements. research have seen how number of unique elements , apparently, have discovered way.
any appreciated. below code.
#!/usr/bin/perl use strict; use warnings; use v5.10; use xml:simple; use lwp::simple; use list::compare; @upd = system ("perl test.pl | grep '*.x86_64.rpm'"); @inst = system ("rpm -qa"); @inst = join( '.rpm', @inst); $ls = list::compare->new( {lists=> [\@upd, \@inst]} ); @list = $ls->get_unique; @list = $ls->get_lonly; "@list";
@upd
contains 1 element, exit status of shell executed perl test.pl | grep '*.x86_64.rpm'
. similarly, @inst
contains 1 element, exit status of rpm
. perhaps trying capture output? use backticks.
my @upd = `perl test.pl | grep '*.x86_64.rpm'`; chomp(@upd); @inst = `rpm -qa`; chomp(@inst);
also, following incorrect:
@inst = join( '.rpm', @inst);
it should replaced following:
$_ .= '.rpm' @inst;
Comments
Post a Comment