The another advantage of this approach compared to other way is you won't lose the rest part of every chunk. you can print any elements of @vals by changing slice.use List::MoreUtils qw/natatime/; my @contents = <DATA>; pop @contents; shift @contents; my $it = natatime 8, @contents; while (my @vals = $it->()) { print "@vals[0,1,2] \n" if $vals[2] =~ /jack/; } __DATA__ start id 10 address Richmond name jack xxxxx aaaaa lastname black yyyy zzzzz id 11 address Central name rick cccccc dddddd lastname hanna eeeee yyyyy id 12 address denver name jack sssss tttttt lastname strong rrrrr mmmmm id 13 address Virginia name mick aaaaaaa ooooooo lastname jagger gggggg hhhhhh id 14 address Maine name rick sssss sssss lastname stewart ssssss ffffff end
I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction
In reply to Re: get n lines before or after a pattern
by xiaoyafeng
in thread get n lines before or after a pattern
by darklord_999
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |