chengchl has asked for the wisdom of the Perl Monks concerning the following question:
Hi Perl Monks,
I have a question about flip flop operator ( /pattern/ .. /pattern/ ) and hope for your instructions/thoughts.
Suppose I have a text file like this :
start text
+ 123
+ 456
+ 789
some other text not starting with +
I would like to extract from "start text" to the one line before "some other text not starting with +". That is to say, in this example, to extract the first four lines.
I wrote a script like this -
===#!/usr/bin/perl use strict; use warnings; my $file = "file_name_to_the_txt"; open(my $fh,'<',$file) or die "Warnings: $!\n"; while (<$fh>) { print if (/^start/ .. /^\+/); } close ($fh);
but it only generates the first two lines. Is there a way to have a greedy flip flop operator? thanks in advance.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Greedy flip flop operator?
by choroba (Cardinal) on Apr 26, 2018 at 08:44 UTC | |
|
Re: Greedy flip flop operator?
by hippo (Archbishop) on Apr 26, 2018 at 08:09 UTC | |
|
Re: Greedy flip flop operator?
by Discipulus (Canon) on Apr 26, 2018 at 07:14 UTC | |
by LanX (Saint) on Apr 26, 2018 at 07:25 UTC | |
by Discipulus (Canon) on Apr 26, 2018 at 07:36 UTC | |
by LanX (Saint) on Apr 26, 2018 at 07:51 UTC | |
by chengchl (Acolyte) on Apr 26, 2018 at 07:56 UTC | |
by LanX (Saint) on Apr 26, 2018 at 08:57 UTC | |
by chengchl (Acolyte) on Apr 26, 2018 at 08:06 UTC | |
|
Re: Greedy flip flop operator?
by poj (Abbot) on Apr 26, 2018 at 07:19 UTC | |
by chengchl (Acolyte) on Apr 26, 2018 at 07:59 UTC | |
|
Re: Greedy flip flop operator?
by tybalt89 (Monsignor) on Apr 26, 2018 at 20:50 UTC | |
|
Re: Greedy flip flop operator?
by RonW (Parson) on Apr 26, 2018 at 19:56 UTC | |
|
Re: Greedy flip flop operator?
by Anonymous Monk on Apr 26, 2018 at 14:24 UTC |