Andrew Lee wrote:
> On 29 Jun 2004 00:32:36 -0700, (David Arnold) wrote:
>
>
>>All,
>>
>>I have a file named "new".
>>
>>\backtomargin
>>
>>
>>In Exercises~\ref{exer2.9.1}--\ref{exer2.9.2}, if the given
>>differential equation is autonomous, identify the equilibrium
>>solution(s). Use a numerical solver to sketch the direction field
>>and superimpose the plot of the equilibrium solution(s) on the
>>direction field. Classify each equilibrium point as either
>>unstable or asymptotically stable.
>>
>>
>>
>>
>>
>>
>>\ex\label{exer2.9.1} $P'=0.05P-1000$
>>
>>The spacing is intentional. Now, my perl file is saved as new.pl.
>>
>>use strict;
>>use warnings;
>>
>># replace \backtomargin with instructions environment
>>my @instructions;
>>my $instruct_line;
>>while (my $line=<>) {
>> chomp($line);
>> if ($line=~/^\s*\\backtomargin/) {
>
>
> But there is no space before "\backtomargin" ... so the following lines never
> get executed.
>
I don't know... It looks to me like there is zero or more spaces before
'\backtomargin'.
Actually, I think the logic problem is the lines:
> while($line=pop(@instructions)) {
and
> while($line=shift(@instructions)) {
Since the first line that gets popped off of the array is a blank line,
the while() short circuits and the code block never gets executed.
Seems to me you are doing an awful lot of extra work chomping off
newlines only to add them back in, and making arrays when you really
want strings. If I was trying to do something similar, I would probably
do something like:
use strict;
use warnings;
my $instructions;
my $instruct_line;
while (<>) {
if ($_ =~ s/^\s*\\backtomargin//) {
$instructions = $_;
while ($instruct_line=<>) {
last if ($instruct_line =~ /\\ex/);
$instructions .= $instruct_line;
}
$instructions =~ s/ *\n/\n/g;
while ($instructions =~ s/\n\n\n/\n\n/) {};
$instructions =~ s/^\n+//;
$instructions =~ s/\n{2,}$/\n/;
print
"\\begin{instructions}\n$instructions\\end{instruc tions}\n\n$instruct_line\n";
} else {
print "$_\n";
}
}
Not knowing what your exact formatting needs were, I took a guess based
on what it /looked/ what you were trying to do.