Problem checking for newline in $_ input line 
Author Message
 Problem checking for newline in $_ input line

Hi, I am working out the last problem in my script to parse fortran
comments (header blocks) and put the information into HTML pages.  I am
having problems checking for the newline in some of the llines of text
being parsed though.

Fortran comment line:

"C *(\n)"

C in column 1, variable number of spaces, variable number of "*" chars.

If I get a line like this in the header block, I want to skip over it,
so I try this:

#  check for blank line after "c *", else strip "c *" and print comment
if (s/^C\s+\*+\n//i)
    {  $ignore_fg = 1;  $purpose_fg = 0;  print "</I> <BR>\n";  }
else
    {  s/^C\s+\*+\s+/ /i;  print $_;   }

Quote:
}

The "^C\s+\*+" part is working as far as I can tell, but it isn't
recognizing the newline "\n" part of the pattern matching.  Any
suggestions?

Jim Cornwall



Sat, 16 Jul 2005 16:17:35 GMT  
 Problem checking for newline in $_ input line

Quote:
>Hi, I am working out the last problem in my script to parse Fortran
>comments (header blocks) and put the information into HTML pages.  I am
>having problems checking for the newline in some of the llines of text
>being parsed though.

>Fortran comment line:

>"C *(\n)"

>C in column 1, variable number of spaces, variable number of "*" chars.

>If I get a line like this in the header block, I want to skip over it,
>so I try this:

>#  check for blank line after "c *", else strip "c *" and print comment
>if (s/^C\s+\*+\n//i)
>    {  $ignore_fg = 1;  $purpose_fg = 0;  print "</I> <BR>\n";  }
>else
>    {  s/^C\s+\*+\s+/ /i;  print $_;   }
>}

>The "^C\s+\*+" part is working as far as I can tell, but it isn't
>recognizing the newline "\n" part of the pattern matching.  Any
>suggestions?

If you're reading a line at a time then you should have chomped it so the \n
isn't even there any more. What you are looking for is C<$>, viz.
end-of-string, thus:

/^C\s+\*+$/

.

Ben



Sat, 16 Jul 2005 17:09:37 GMT  
 Problem checking for newline in $_ input line
Quote:


>>Hi, I am working out the last problem in my script to parse Fortran
>>comments (header blocks) and put the information into HTML pages.  I am
>>having problems checking for the newline in some of the llines of text
>>being parsed though.

>>Fortran comment line:

>>"C *(\n)"

>>C in column 1, variable number of spaces, variable number of "*" chars.

>>If I get a line like this in the header block, I want to skip over it,
>>so I try this:

>>#  check for blank line after "c *", else strip "c *" and print comment
>>if (s/^C\s+\*+\n//i)
>>   {  $ignore_fg = 1;  $purpose_fg = 0;  print "</I> <BR>\n";  }
>>else
>>   {  s/^C\s+\*+\s+/ /i;  print $_;   }
>>}

>>The "^C\s+\*+" part is working as far as I can tell, but it isn't
>>recognizing the newline "\n" part of the pattern matching.  Any
>>suggestions?

> If you're reading a line at a time then you should have chomped it so the \n
> isn't even there any more. What you are looking for is C<$>, viz.
> end-of-string, thus:

> /^C\s+\*+$/

> .

> Ben

Argh...  (or is D'OH!! more appropriate?)  Thank you, I will change
that.  I did have a chomp at the top of the loop.

Jim



Sat, 16 Jul 2005 17:45:25 GMT  
 Problem checking for newline in $_ input line

Quote:
> Hi, I am working out the last problem in my script to parse Fortran
> comments (header blocks) and put the information into HTML pages.  I am
> having problems checking for the newline in some of the llines of text
> being parsed though.

> Fortran comment line:

> "C *(\n)"

> C in column 1, variable number of spaces, variable number of "*" chars.

> If I get a line like this in the header block, I want to skip over it,
> so I try this:

> #  check for blank line after "c *", else strip "c *" and print comment
> if (s/^C\s+\*+\n//i)
>     {  $ignore_fg = 1;  $purpose_fg = 0;  print "</I> <BR>\n";  }
> else
>     {  s/^C\s+\*+\s+/ /i;  print $_;   }
> }

> The "^C\s+\*+" part is working as far as I can tell, but it isn't
> recognizing the newline "\n" part of the pattern matching.  Any
> suggestions?

> Jim Cornwall


Hi Jim:

You probably want to look at the "s" and "m" switches for regexes.
Without them your regex will work only "up to" the first \n.

Cheers,
Gx



Sat, 16 Jul 2005 22:27:47 GMT  
 Problem checking for newline in $_ input line

Quote:


>> if (s/^C\s+\*+\n//i)
> You probably want to look at the "s"

s///s will not change anything.

The "s" option changes the meaning of the dot metacharacter, it
has no effect (other than making the maintainer "hiccup" in
understanding it) when there is no dot in the pattern.

(I don't remember fortran ignoring case. Does it?)

Quote:
> and "m" switches for regexes.

That one he _does_ need.

s///m changes the meaning of the ^ and $ anchors.

--
    Tad McClellan                          SGML consulting

    Fort Worth, Texas



Sat, 16 Jul 2005 23:31:49 GMT  
 Problem checking for newline in $_ input line

Quote:



> >> if (s/^C\s+\*+\n//i)

> > You probably want to look at the "s"

> s///s will not change anything.

> The "s" option changes the meaning of the dot metacharacter, it
> has no effect (other than making the maintainer "hiccup" in
> understanding it) when there is no dot in the pattern.

> (I don't remember fortran ignoring case. Does it?)

> > and "m" switches for regexes.

> That one he _does_ need.

> s///m changes the meaning of the ^ and $ anchors.

> --
>     Tad McClellan                          SGML consulting

>     Fort Worth, Texas

A solution that works is:

  if ($purpose_fg == 1)        # no, are we in the PURPOSE block?
    {
     if (s/^C\s+\*+$//i)       # detect and strip out blank comment
lines
       {  $ignore_fg = 1;      # set flag to ignore further input till
next keyword
          $purpose_fg = 0;          # unset this flag
          print "</I> <BR>\n";  }   # close HTML 'line'
     else
       {  s/^C\s+\*+\s+/ /i;        # non-blank comment, strip off "C *"
and
          print $_;   }             # print the line
     }

My biggest problem was in looking for a \n after having done a chomp on
the line.  Ben's suggestion to look for the $ instead did the trick.

And yes, Fortran is case-insensitive.  

Thanks,
             Jim
--

****************************************************
** Facilior veniam posterius quam prius capere!   **
****************************************************
** James F. Cornwall, sole owner of all opinions  **
**  expressed in this message...                  **
****************************************************



Sun, 17 Jul 2005 15:26:47 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Newbie needs help: Checking input after blank line

2. How to check for Null input or spaced input

3. Stripping Newline Characters from Form Input

4. Help: Slice with newlines from a form input

5. Problem checking if a command line option has been specified using Getopt::Long

6. newline problem with messy output - v simple problem

7. Multi-line substitution (adding newlines and global replace)

8. Split string into newline-terminated lines

9. Replacing multiple occurences of newline chars with a single newline char

10. Newbie Question: check form input

11. checking for input

12. Checking user input from a form against a data file

 

 
Powered by phpBB® Forum Software