Robert's Perl Tutorial

http://www.sthomas.net/roberts-perl-tutorial.htm


Quote execute

@opts=qw(w on ad oe b);

for (@opts) {
	$result=qx(dir /$_);
	print "dir /$_ resulted in:\n$result",'-' x 79;
	sleep 1;
}

Anything within qx( ) is executed, and duly variable interpolated. This sample also demonstrated qw which is 'quote words', so the elements of @opts are delimited by word boundaries, not the usual commas. You can also use for instead of foreach if you want to save typing four character for the sake of legibility.

You may have noticed that system outputs the result of the command to the screen whereas qx does not. Each to its own.