Difference between for & foreach,exec & system?

Showing Answers 1 - 2 of 2 Answers

Joe Doe

  • Jul 8th, 2006
 

- Technically, there's no difference between for and foreach other than some style issues.



One is an alias of another. You can do things like this



foreach (my $i = 0; $i < 3; ++$i)

{ # normally this is foreach print $i, "n";}



for my $i (0 .. 2)

{ # normally this is for print $i, "n";}



- exec runs the given process, switches to its name and never returns while system forks off the given process, waits for it to complete and then returns.

VINOD

  • Jul 22nd, 2012
 

For is iterating thorough indices and foreache is iterating through element value.

Exec will execute the command and will not return to the same program from which it was called. System will also execute the command and it will return back to same program from which it was called.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions