What is the difference between for & foreach, exec &
system?

Answer Posted / mukesh

for and foreach are alias of each other.But syntax is different.

e.g for(my $i = 0; $i < 3; ++$i){print $i}
e.g foreach my $i (0 .. 2){print $i}

i.e in foreach we can take always only array of elements or
range of elements.But in for we dont have to take the array
or range always.here we can provide condition of the loop
where it is not true for foreach.

Is This Answer Correct ?    28 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the advantages of perl programming?

749


How do I read command-line arguments with Perl?

785


What are the arguements we normally use for perl interpreter?

717


What is a chomp() function in perl?

726


What is stdin in perl?

723


Explain the default scope of variables in perl?

699


What are the advantages of c over Perl?

722


Explain the difference between declarations of 'my' and 'local' variable scope in perl?

709


What is “grep” function in perl?

743


what are the two ways to get private values inside a subroutine or block?

706


What are the different types of perl operators?

726


Explain the functioning of conditional structures in perl.

654


What are scalars in perl?

708


How do you find the length of an array?

722


How to read a directory in perl?

730