cxfcxf has asked for the wisdom of the Perl Monks concerning the following question:
i want it to bea begin 1 <----- delete a <----- delete 2 <----- delete end c begin c end a begin 1
i wrote my own code...but...it's to complex...a begin end c begin c end a begin 1
is there some simple way to do so? thanks!#!/usr/bin/perl use strict; use warnings; my @array = <DATA>; my $count = 0; my $fb = 0; foreach (@array) { if (/begin/) { $fb = $count; last; } $count++; } $fb++; my $count1; my $fc = 0; foreach (@array) { if (/end/) { $fc = $count1; last; } $count1++; } my $num = ($fc - $fb); splice (@array,$fb,$num); print @array; __DATA__ a begin 1 a 3 end c begin c end a begin 1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how to cut context between first "begin" and "end"?
by snoopy (Curate) on Sep 02, 2009 at 04:30 UTC | |
|
Re: how to cut context between first "begin" and "end"?
by jwkrahn (Abbot) on Sep 02, 2009 at 06:03 UTC | |
|
Re: how to cut context between first "begin" and "end"?
by spazm (Monk) on Sep 02, 2009 at 08:50 UTC |