[comp.lang.perl] how to recognize multi-line things, and ? about regexp return status

thoth@camellia.cis.ufl.edu (Gilligan) (08/27/90)

  Someone asked how to match a Recived and then a following line
beginning with blanks.  I pressed the wrong key in gnus and lost the
article.
  When you run a sed script through s2p, certain codes like N get
translated into something like this:

while (<>) {
  if (/^int$/) { $_ .= <>; }
  if (s/^int\ncmd(X[a-zA-Z0-9]*)\(.*$/$1/) {
...

  The first if check to see if the line matches the first line of the
pattern.  If so it appends the next line and then checks against the
longer pattern.  I doubt this is good perl since I'm a novice, but it
does get the job done.
  CAVEAT:  It will not match

int
int
cmdXStoreName(

  because the first int eats the second.  The hack-arounds are left as
an exercise to the reader.

----

  On another note, I wrote a perl script that reads old XPM files and
translates them into XPM2 files.  The code looks like this:


sub checkname {
if ($_[0] ne $_[1]) { printf STDERR "warning, name inconsitencies in %s %s!=%s\n", $_[2], $_[0], $_[1]; }
}

printf "/* XPM2 C */\n";
($name, $format) = (<> =~ /^#define (\w+)_format (\d+)$/);
($name2, $width) = (<> =~ /^#define (\w+)_width (\d+)$/);
&checkname($name, $name2, "width");
($name2, $height) = (<> =~ /^#define (\w+)_height (\d+)$/);
&checkname($name, $name2, "height");

  And there are even more pattern matches following.  What's the best
(read fewest-characters) way to check for error status from the regexp
matches.  I've been overwhelmed by the man page.

--
/--------------------
"a window is a terrible thing to paste" -me
( My name's not really Gilligan, It's Robert Forsman, without an `e' )
--------------------/