[oclug]Really basic Perl help

Brian's Linux Box b_mckee at myrealbox.com
Tue Jan 7 10:39:31 EST 2003


Pardon me - I haven't tried this to see what it puts out - but remember I
want everything *between* two specific comments - the comments themselves
are optional.  E.g.:

<b>Don't capture this</b>
<!-- Content -->
   Capture from the start of this line...
<a href="http://www.oclug.on.ca">Click here</a><br>
For a local group who can be very helpful.
<a href="http://www.microsoft.com">Or here - if you insist</a>
   To the end of this line
<!-- Content -->
<b>Don't capture this</b>

The line below about "local $/;" looks interesting - does it ignore line
delimiters when matching? Or remove them from $_?

Brian

> On Mon, Jan 06, 2003 at 08:25:28PM -0500, Milan Budimirovic wrote:
>> Again, it's simple if the comment is always going to appear on a single
>> line. But what if it's
>> 
>> <!-- this could be a very long comment spread out
>> over two or more lines -->
> 
> local $/;          # no line delimiter
> $_=<>;             # slurp whole file
> /<!--(.*?)-->/s    # match *first* comment
> and print "$1\n"  # print it
> 
> If you want a multi-comment array, try something like
> 
> while(/<!--(.*?)-->/sg){ push @comment,$1 }
> 
> Joe




More information about the OCLUG mailing list