CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Subtract two arrays

 



dwarnold45
Novice

Jul 19, 2011, 4:38 PM

Post #1 of 3 (813 views)
Subtract two arrays Can't Post

All,

If I have @a=(5,6,7) and @b=(1,1,1), what's the best way to find the difference @d=(4,5,6)?

D.


BillKSmith
Veteran

Jul 19, 2011, 7:57 PM

Post #2 of 3 (802 views)
Re: [dwarnold45] Subtract two arrays [In reply to] Can't Post

Use the function pairwise in the module List::MoreUtils. Refer: perldoc List::MoreUtils.
Good Luck,
Bill


miller
User

Jul 23, 2011, 2:47 AM

Post #3 of 3 (775 views)
Re: [dwarnold45] Subtract two arrays [In reply to] Can't Post


Code
my @a = (5,6,7); 
my @b = (1,1,1);

my @d = map {$a[$_] - $b[$_]} keys @a;

print "@d";


- Miller

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives