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

How to determine strings length in perl?

539


How to compare two strings in perl?

549


Explain chop?

539


What is q (single q) operator in perl?

537


What is the syntax used in Perl grep function?

596






How the interpreter is used in Perl?

534


In Perl we can show the warnings using some options in order to reduce or avoid the errors. What are that options?

591


How to sort arrays in perl?

631


What is automatic error handling in perl?

505


What is perl programming?

563


What is boolean context?

553


Explain the execution of a program in perl.

506


Explain the default scope of variables in perl?

518


What is perl scripting?

517


What is the use of '>>' in perl?

541