Interacting with the Shell
Perl allows you to run system functions within your code.You can list the content of a folder with Perl or pretty much anything that the shell can. However why use Perl code when it is so convinient to use shell commands. It has its drawbacks of course, as using shell commands your script will only work where there is a compatible shell. It is also a lot easier and faster to go through the shell for some of the common functions of your script.
Example :
#!/usr/bin/perl –w
System “ls –la”;#display content of directory on *nix systems
System “dir”;# display content of directory on dos/windows systems
#END
You may see in some script the use of “exec” in place of “system” it would return the same result, however we strongly suggest you not to use it for 2 reasons. The first is that exec is old and will eventually be depreciated in following versions of Perl. The second is that exec does not return the status of the execution to the system. It means that if it doesn’t work you cannot know why “$?” will not be updated by exec.