Re: very new - need help with regular expressions

From: John W. Krahn (krahnj_at_telus.net)
Date: 03/27/05


To: beginners@perl.org
Date: Sat, 26 Mar 2005 21:55:59 -0800

Brett Williams wrote:
> Hi :)

Hello,

> I am still very new to perl (and programming) and am getting stuck with
> regular expressions. I have a text file in which I want to find, then
> print to screen all lines beginning with "?" and then print the text
> between the "<" and ">" characters. The code I have tried (amongst many
> variations) is below
>
> (open(INPUT, "record.txt")) || die("Error, can't find file\n");
> $line = readline(INPUT);
> while($line =~ /^\?/)
> {
> chomp($line);
> print($line =~ /(.+)<\/a>\]/);
> $line = readline(INPUT);
> }
> close(INPUT);

open INPUT, '<', 'record.txt' or die "Error, can't open 'record.txt' $!";

while ( <INPUT> ) {
     next unless /^\?/;
     print "$1\n" if /<([^>]+)>/;
     }

close INPUT;

John

-- 
use Perl;
program
fulfillment