On 3/20/07, Dukelow, Don <[EMAIL PROTECTED]> wrote:
First off thanks to the several e-mail I got for my old way of thinking
with the divide question I had earlier this morning.
Next I'm tiring to increment a scalar variable name by one each time
through a for loop.
$pid1
$pid2
$pid3
And so on
The code I'm running is
54 For (my $n = 1; $n <= $FORK_COUNT; $n++) {
55 unless ($pid.$n = fork()) {
56 &run_script();
57 exit();
58 }
69 }
The error I get is
Can't modify string in scalar assignment at <script name> line 55, near
")) "
What I'm tiring to do is control the number of forks I run by changing
one variable $FORK_COUNT. Which also splits a feeder file accordingly
for each fork
Or if someone has a better idea to do this I'm open for suggestions
Don Dukelow
Whenever you think to yourself "I want to have variables named var1,
var2, var3" instead say to yourself "that is an array named var with
indexes of 0, 1, and 2". Here is your code with an array (I have also
changed some of your code to be more Perlish):
#!/usr/bin/perl
use strict;
use warnings;
use POSIX ":sys_wait_h";
my @pid;
for my $n (1 .. $FORK_COUNT) {
my $pid = fork;
die "could not fork" unless defined $pid;
if ($pid) {
push @pid, $pid;
} else {
run_script(); #don't use &func() unless you know exactly why
you are doing it
exit();
}
}
for my $pid (@pid) {
print "I started $pid\n";
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/