very simple question:execute unix command inside script

Hello,
How can I execute unix commands like "ls" ,"date" inside perl script and print output to a file?

thanks
tianAsked:
Who is Participating?
 
martinagCommented:
# This puts the output from date function in $date.
# Be sure to use backticks!
$date = `date`;

# Print result to output.txt
open (OUTPUT, ">output.txt") or die "can not open file: $!";
print OUTPUT $date;
close OUTPUT;
0
 
tianAuthor Commented:
Edited text of question
0
 
ozoCommented:
and if you're specifically interested in `ls` and `date`,
it would be faster and more portable to use the built in readdir and localtime functions.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.