I really appreciate your expertise.
Thank you mate.
> On Jun 4, 5:54 am, "SimonH" <s
@bigpond.net.au> wrote:
>> Hi guys!
>> I have the following script which opens a machine.txt file, with format:
>> machine1
>> machine2
>> machine3
>> etc
>> ====================================================
>> #!perl
>> open (INPUT,"machine.txt") or die "cant open machine.txt";
>> @computers = <INPUT>;
> This statement reads ALL lines of machine.txt into @computers. There
> is nothing left to read at this point.
>> while (<INPUT>) {
>> chomp;
>> push @computers, $_;}
> This block is therefore a no-op. There is nothing left to read, so
> this loop is never executed.
>> foreach $a (@computers) {
> If you're just going to process the data line-by-line anyway, it makes
> no sense to bother reading the entire thing into an array. Get rid of
> the first statement, keep the second block, and put the following code
> into that block. So:
> while (my $computer = <INPUT>) {
> (I changed your $a to $computer, because $a and $b are "special" in
> Perl, and should generally only be used for sort subroutines)
>> if ($a eq "dell101\n") {
>> print "hi there simon\n";
>> print `notepad`;
>> }
>> else {
>> print "you are not my machine\n";
>> }
>> Is there any way to spawn other processes, but continue execution
>> of your original script?
> Yes. Fork a new process, and exec the program in the new child
> process.
> perldoc -f fork
> perldoc -f exec
> if (fork()) { #parent
> do_parent_stuff();
> } else { #child
> exec 'notepad.exe';
> }
> Depending on your shell, you might also be able to just put a '&' at
> the end of the command you want to run, to tell the shell to run the
> process in the background. I have no idea how or if that works in
> Windows, however.
> Paul Lalli