SparkeyG has asked for the wisdom of the Perl Monks concerning the following question:
I'm working on the regular Perl Quiz of the Week, and while I've got it solved, I don't understand why I had to do something to dwiw. The included code shows the pertinant problem.
I take a line of the box to be put into the output. $putNum is a boolean variable. The problem is that instead of updating $boxLine with the current word number, it continues to put in the number 1.
The problem went away if I instead use a seperate variable in the foreach line and then later assign its value to $boxLine.
Please help me understand why this is happening.
my $wordNum = 0; foreach my $boxLine ( @empty_square) { if ($putNum) { $wordNum ++; my $space = $boxLine =~ s/\./\./g; my $string = sprintf "%-*d", $space, $wordNum; $boxLine =~ s/\.+/$string/o; } else { $boxLine =~ s/\./ /g; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Question of variable interpolation in regex
by tommyw (Hermit) on Nov 15, 2002 at 16:51 UTC | |
by thelenm (Vicar) on Nov 15, 2002 at 16:56 UTC | |
Re: Question of variable interpolation in regex
by SparkeyG (Curate) on Nov 15, 2002 at 16:56 UTC | |
by l2kashe (Deacon) on Nov 15, 2002 at 19:27 UTC | |
by SparkeyG (Curate) on Nov 15, 2002 at 19:48 UTC | |
by Thelonius (Priest) on Nov 15, 2002 at 17:17 UTC | |
Re: Question of variable interpolation in regex
by Thelonius (Priest) on Nov 15, 2002 at 22:40 UTC |
Back to
Seekers of Perl Wisdom