grep in perl without array -
If I have a variable: I sent it to the full text file
$ var = file Suppose the "I" word is in the 17th row (space is not available, but the only example given) and I want to find after a pattern of the word 'I N (such as 10) the word' I ' If the pattern 'words' exist in those lines or not, how can I do that without regular expressions of the array Switch to Example:
$ var = "I'm good at Pearl \ n But I would like to know about this \ N details grep command"; I want to find special patterns in special lines (line 2 to 3 only). How can I do this without using the array?
There is a legitimate case to not use arrays - When the file is larger than prohibited.
Instead of having to beat around the bush to find Perl idiom is a very specific need, I Upastratin write:
sub n_lines_apart {my ($ file, $ N, $ first_pattern, $ second_pattern) = @_; My $ FH, '& lt;', Open $ file or $ !! My $ lines_apart; While (& lt; $ fh & gt;) {$ lines_apart ++ if qr / $ Phle_patn / .. qr / $ second_pattern /; } $ Lines_apart & amp; Amp; $ Lines_apart & lt; = $ N + 1; } Warning Deputy is not designed to handle multiple matches in the above single file. Give it an exercise for the reader.
Comments
Post a Comment