Perl/Shell Knowledge Sharing
Perl Interview Questions and Answers
Friday, December 31, 2010
Add Two Arrays
@array1 = (1, 2, 3);
@array2 = (4, 5, 6, 7);
if(@array1 > @array2) {
$len = @array1;
}
else {
$len = @array2;
}
for($i = 0; $i < $len; $i++) {
push(@sum, ($array1[$i]+$array2[$i]));
}
print "@sum";
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment