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 arguements we normally use for perl interpreter?

521


List the prefix dereferencer in Perl.

578


Explain subroutine?

536


How to concatenate strings with perl?

482


Create a function that is only available inside the scope where it is defined ?

558






What is the difference between single (') and double (") quote in a string in perl?

490


Explain split function in perl?

567


How can we create perl programs in unix, windows nt, macintosh and os/2 ?

496


Explain the various characteristics of perl.

536


Give an example of using the -n and -p option.

550


How do I read command-line arguments with Perl?

612


What are some common methods to all handles in perl?

514


how to create a flat file database as shown below s.no name age city phone 0 hema 22 Calcutta 4312542 1 hema 21 Bangalore 2344345 2 ganesh 25 delhi 2445454 3 kartik 45 pune 4312121 4 santosh 25 Hyderabad 2254231 5 kumar 25 mysore 2344567 6 gita 34 mangalore 6532123 7 gita 32 pune 2213456 Q1.print the details of the person who r from bangalore q2.Replace the city name managlore to pune q3.prints no of person having name gita and hema q4.print how many are of age 25.

1684


How to prevent file truncation in perl?

512


Which operator in perl is used for the concatenation of two strings?

511