develooper Front page | perl.beginners | Postings from February 2002

pattern matching question

Thread Next
From:
richard noel fell
Date:
February 28, 2002 08:09
Subject:
pattern matching question
Message ID:
3C7E5CCA.C811E0AE@rcn.com
I have the following bit of code:
#!/usr/bin/perl -w
open In2,"/home/rfell/tutoring/beaven/webproject/tmp/maxima_log" or die
"Cannot open maxima_log:$!";
my $Line; 
while (defined($Line=<In2>)){
  if($Line=~/(\(D\d+\))\s*(\w*)/){
print "==> $2\n";
};
};
#close In2;



maxima_log is the following

GCL (GNU Common Lisp)  Version(2.4.0) Wed May  9 12:02:00 CDT 2001
Licensed under GNU Library General Public License
Contains Enhancements by W. Schelter
Maxima 5.6 Wed May 9 12:01:49 CDT 2001 (with enhancements by W.
Schelter).
Licensed under the GNU Public License (see file COPYING)
(C1) 
				      2335
(D1) 				    - ----
				       24
(C2) 
(D2) 				       0
(C3) 
(D3) 	   /home/rfell/tutoring/beaven/webproject/tmp/maxima_results
(C4) 

I want to match the D lines, so my match pattern is as above. It seems
that I have the following construct:
(D followed by a digit(s)) followed by white space followed by some
characters. I want to capture the last characters. In the above example,
for line (D2), I want to get the "0", which is stored, I hope, in $2.
However, I get no match. If I replace $2 with $1, I do get the (D1), etc
to print.

Another question
1) If I change the match pattern to /(\(D\d+\))\s+(\w*)/, that is, one
or more occurences of white space, I get no match at all. $1 does not
print out now. Do I not really have white space?

Has anyone any idea what I am doing wrong? Thanks for your help to a
perl newcomer.
Dick Fell

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About