- Home
- Interview Questions
- Perl
You can’t do that. Well, not right now. To create arrays of arrays, or arrays of hashes, or any kind of nested data structures, you need to use references.
Not necessarily. Array elements are indexed by number, and the relationship between an element and its index might be important. By deleting an element, you’d end up renumbering all the elements in the farther down in the array, which might not be what you want to do. The delete function does the safe thing and just adds an undef placeholder (except if the element to be deleted is the last element, in which case it’s considered safe to remove it). You can always reconstruct the array if you really want those elements deleted.
One way would be to iterate over the array using a foreach or while loop, and test each element of that array in turn. Perl also has a function called grep (after the Unix search command) which will do this for you
A list is simply a collection of scalar elements. An array is an ordered list indexed by position.
There is no rule for converting a list into a scalar. You can't even convert a list into a scalar. Lists behave differently in a scalar context depending on how you use them.
The %ENV hash holds the variable names and values for the script’s environment. On Unix and Windows, the values in this hash can be useful for finding out information about the system environment (or for changing it and passing it on to other processes). On the Mac %ENV doesn’t serve any useful purpose.
The system command runs some other program or script from inside your Perl script and sends the output to the standard output. Backquotes also run an external program, but they capture the input to a scalar or list value (depending on context).
Multiple processes are useful for portioning different parts of your script that might need to be run simultaneously, or for splitting up the work your script needs to do.
The fork function creates a new process, a clone of the original process. Both the new processes continue executing the script at the point where the fork occurred.
Win32::Process and fork are not interchangeable. The fork function ties very strongly to processes on Unix; Win32::Process is more analogous to a fork followed immediately to an exec.