Hi again!!

#!/usr/bin/perl -w

print $ENV{'HOMEPATH'};
print ">";
chomp($newdir = );
chdir($newdir) ||
die "cannot chdir to $newdir: $!";
opendir(DOT, ".") ||
die "cannot open dir . $!";
foreach (sort readdir(DOT)) {
print "$_
closedir (DOT);

I have written this code where the program starts in my homecatalog..

Say I want to execute a program under..say C:Program...what do I write in my code then?

system('ping'); My last answer I get whas this but it dident tell me much - Iam pretty new to this as you understand now



  • The system() function (well, syscall) runs a shell command from the cwd of the perl script (which is the directory it's being run from, not where it is on the hard drive) and prints the output. It returns the exit status, which is useful if you want to check for failure. Therefore, [grey]system("dir")[/grey] will print the contents of your current directory.

    You can also use backticks (or the qx construct), which give the output to be stored in a variable. Thus, [grey]print `dir`[/grey] is the same as [grey]system('dir')[/grey], but slower, and [grey]my $dir = `dir`; print $dir[/grey] is the same again but even slower and more wasteful of resources (unless you need to do something with the output as well as print it, in which case it would be faster and more reliable than doing [grey]system(); $foo = ``[/grey].)
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion