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

pattern matching question

Thread Next
richard noel fell
February 28, 2002 08:09
pattern matching question
Message ID:
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>)){
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.
Licensed under the GNU Public License (see file COPYING)
(D1) 				    - ----
(D2) 				       0
(D3) 	   /home/rfell/tutoring/beaven/webproject/tmp/maxima_results

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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About