in reply to Text matching repost
How about a different approach?
Edit: Added comments, removed unnecessary regex escaping
Glad I've finally found a useful non-numeric-iterating purpose for .. :)#!/usr/bin/perl use strict; use warnings; my ($start, $stop) = (qr '#ifdef|#if defined', qr '#endif'); open INPUT, '<', 'monks23.dat' or die "Error opening input: " . $!; while (<INPUT>) { if (/$start/ .. /$stop/) { # Print the lines themselves if (/$start/ or /$stop/) { print; } # Skip the rest next; } print; } close INPUT;
Edit: Added comments, removed unnecessary regex escaping
In Section
Seekers of Perl Wisdom