On Feb 8, Steven M. Klass said:
>I am having some problems and I can't seem to get it right. In short, I
>want to only modify text in a specific section. That section is denoted
>by the following
>
<snip>
>*DESCRIPTION
>
><multiple line of text to be edited>
>
>*END
><snip>
This sounds like a job for the .. operator. Let's see.
>Here is what I have. I know the problem, I am reading this line by line so
>when I find the DESCRIPTION I drop into the loop, but because I still have
>DESCRIPTION obviously I won't search and replace.
>
>open (RUNSET, $FLOW) || die "Can't access $FLOW[0][1]\n";
>while (<RUNSET>) {
> if ($_ =~ m/DESCRIPTION/){
> print "Entering description block";
> until ( $_ =~ m/END\.){
The problem is that you never read from <RUNSET> in this until() loop, so
$_ is never given the new line, and the loop goes on forever. If you add:
$_ = <RUNSET>;
here, it might work.
> print "Entering until";
># next if /;/ # Remove Comments
> s/^\ INDISK\s+=.*/ INDISK = $FILENAME ; SMK /;
> s/^\ PRIMARY\s+=.*/ PRIMARY = $CELLNAME ; SMK /;
> }
> }
> print TEMPFLOW "$_";
># push @runset, $_ ;
>}
But here's the Perlish way to write it:
while (<RUNSET>) {
if (/DESCRIPTION/ .. /END/) {
# do the following in between a line matching
# /DESCRIPTION/ and a line matching /END/
s/^ INDISK\s+=.*/ INDISK = $FILENAME ; SMK /;
s/^ PRIMARY\s+=.*/ PRIMARY = $CELLNAME ; SMK /;
}
print TEMPFLOW;
}
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]