[EMAIL PROTECTED] wrote:
Thanks Jenda, Chas.Owens and fellow members.
What do you mean by "globalise"?
Jenda
Looking at the script below, in diagram 1, $capital will not be
incremented unless I write it as in diagram 2.
Just because I do not want $capital to be reset on each foreach loop, I
then have to declare $capital as in diagram 2. This seems to defeat the
purpose of using the "use strict" pragma.
Thanks
#####diagram 1#########
use strict;
my $banker = 5;
my $player = 3;
my $stake = 1;
foreach (qw/1..10/){
You have a list with one element, in other words:
foreach ( '1..10' ) {
If you really meant to generate the list 1,2,3,4,5,6,7,8,9,10 then you
have to do it like this:
foreach ( 1 .. 10 ) {
But instead of using a loop you could just do this:
my $capital = $stake * 10 if $banker > $player;
if ($banker > $player){
my $capital += $stake;
}
}
#### diagram 2 ###########
use strict;
my $banker = 5;
my $player = 3;
my $stake = 1;
my $capital = 1;
foreach (qw/1..10/){
if ($banker > $player){
$capital += $stake;
}
}
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/