Re: need to go back three lines after a match
From: Michael Budash (mbudash_at_sonic.net)
Date: 10/04/03
- Next message: sts_at_news.sts: "REGEX (Not allowing file extenstions) or the dot"
- Previous message: smackdab: "hack a telnet server?"
- In reply to: Andrew Rich: "need to go back three lines after a match"
- Next in thread: ko: "Re: need to go back three lines after a match"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 03 Oct 2003 22:55:57 GMT
In article <3f7df944_1@news.iprimus.com.au>,
Andrew Rich <vk4tec@hotmail.com> wrote:
> Howdy,
>
> I have a need to do this :-
>
> 1. find a match
> 2. go back three lines
> 3. read out lines 1 2 3
>
> eg
>
> apples
> bannanas
> oranges
>
> match on oranges
>
> back up three lines, output three lines
>
> apples
> bannanas
> oranges
>
how bout this:
while (<DATA>) {
push @queue, $_;
shift @queue if @queue == 4;
if (/oranges/) {
print @queue;
last;
}
}
__DATA__
pears
apples
bananas
oranges
peaches
-- Michael Budash
- Next message: sts_at_news.sts: "REGEX (Not allowing file extenstions) or the dot"
- Previous message: smackdab: "hack a telnet server?"
- In reply to: Andrew Rich: "need to go back three lines after a match"
- Next in thread: ko: "Re: need to go back three lines after a match"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|