Re: regex newbie question

From: A. Sinan Unur (1usa_at_llenroc.ude.invalid)
Date: 03/28/05


Date: Mon, 28 Mar 2005 02:05:55 GMT


"ZMAN" <vze2mf4r@verizon.net> wrote in news:0nJ1e.21235$uw6.16103
@trnddc06:

> Reading in lines from a file.
> I want to ignore all the text before it gets to the line
> "<!--document_starts_here-->"
> and write out the remainder of the text to a file.

use strict;
use warnings;

missing.

> open DATAOUT, ">$data_file" or die "can't open $data_file $!";

open my $data_out, '>', $data_file or die "Can't open $data_file: $!";

See

perldoc -q always

The question, of course, is where are you reading the data in?

> foreach $line (@lines)
> {
>
> if ($line =~ m/<!--document_starts_here-->/i)
> {
> print "This line contains the word : $line\n";
>
> #### write remainder of file out
> }
>
> print DATAOUT "$line";
>
> }
>
>
> close (DATAOUT)

Please post real code. Please see the posting guidelines for this group
to find out how you can help others help you.

It *seems* to me like you are initially slurping the file. There is no
need for that.

#! /usr/bin/perl

use strict;
use warnings;

while(<DATA>) {
    next unless /<!--document_starts_here-->/i;
    while(<DATA>) {
        print;
    }
}

__END__
<html>
<head>
<title>Test</title>
</head>

<!--document_starts_here-->
<body>
<h1>Some document</h1>
<p>ya ba da ba doo</p>
</body>
</html>



Relevant Pages