CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [tsdjim] Select lines in a file between pattern: Edit Log



Chris Charley
User

Aug 28, 2017, 1:22 PM


Views: 3696
Re: [tsdjim] Select lines in a file between pattern

To exclude the pattern line, say print unless . . .


Code
#!/usr/bin/perl 
use strict;
use warnings;
use Time::Piece;

open my $fh, '<', \<<EOF;
Auguststart
Some text
some more text
Augustend
Septemberstart
Some text
some more text
Septemberend
EOF

my $month = localtime->strftime("%B");

while (<$fh>) {
if (/^${month}start$/../^${month}end$/) {
print unless /^$month(?:start|end)$/;
}
}


(Note that I used Time::Piece to get the name of the month. It will eliminate the need to enumerate the month names as your and Bill's code does).


(This post was edited by Chris Charley on Sep 3, 2017, 1:40 PM)


Edit Log:
Post edited by Chris Charley (User) on Sep 3, 2017, 1:40 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives