Re: Regular expression over multiple lines issues



glenn.pringle@xxxxxxxxx wrote:
My problem is that the regular expression is only displaying the first
item (mrn) but it won't display the others (enc, date,
report_subtitle)

My code is on the following line

#!/usr/bin/perl

#open(FILE, "3688001.ps");
open(FILE, "1234567.txt");

while ($buf = <FILE>) {

Since your regex spans over multiple lines, you can't just read one line at a time.

local $/ = "end\n";
while (my $buf = <FILE>) {

Read about the $/ variable in "perldoc perlvar".

#print "$buf\n";

if ($buf =~ m/\%mrn\%(\d+).+
\%enc\%(\d+).+
\%date\%
(\d{1,2})\/
(\d{1,2})\/
(\d{1,2})\^.+

Year may have four digits.

(\d{2,4})\^.+

^\%report_subtitle\%(.+)\(

You probably want that to be non-greedy.

^\%report_subtitle\%(.+?)\(

Read about greediness in "perldoc perlre".

/xms) {

<snip>

I would appreciate if anybody can tell me what I'm doing wrong or
missing.

See comments above.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
.



Relevant Pages

  • Re: adding comma seperated values from a multi line file and displaying data
    ... together and display the sum. ... display those numbers on a single line. ... perldoc perlintro ... value, and processing it - either adding it to the relevant sum, or ...
    (perl.beginners)
  • Re: Perldoc versus Man
    ... TM> It knows how to display the docs for modules installed from CPAN. ... if you have normal pod, ... perldoc can do that man can't. ... about the docs than man can (stuff like searching or indexing). ...
    (comp.lang.perl.misc)
  • Re: Perldoc versus Man
    ... TM> And perldoc knows even more than all that. ... TM> It knows how to display the docs for modules installed from CPAN. ... reading pod, man or some podtool? ... if you write normal pod and do a normal Makefile.PL (or ...
    (comp.lang.perl.misc)
  • Re: Time Conversion
    ... Is there a way to, within Perl, translate Unix times to ... > Universal times when I display the input? ... Use gmtimeto get components of UTC time from Unix time ... perldoc -f localtime ...
    (comp.lang.perl.misc)
  • Re: Perldoc versus Man
    ... > EW> Is there any content and usability difference between ... > and that is what those extra options do. ... And perldoc knows even more than all that. ... It knows how to display the docs for modules installed from CPAN. ...
    (comp.lang.perl.misc)