Hi, Is there a way to store the output of a system call on unix?
eg. system("date");
I like to store the date output to a variable. The only way I know of is to open and write the output to a file and then read in to a variable. Is there a simpler way?
Thanks in advance.
Geraldine
As the others have mentioned you can use the backticks to store the output. But please only use this method when it is absolutely necessary. Perhaps you just gave an example, but in case not, you can get the current date from Perl itself much easier and much more safely.
Shelling out to a command using system or backticks is a *last resort*. If there is something you don't know how to do in Perl or if it can be done in Perl ask first, use 'system' et al second.
You need to check the return value of system, and whether the program executed at all, you should consider full paths, make sure you have taint checks on, and be sure to read the documentation for the program you are calling thoroughly to understand its interface. In general shelling out is slower, more error prone, less secure, and when done right takes longer to code.
http://danconia.org
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>