- Where Developers Learn, Share, & Build Careers
If I have a variable: I've sent it a complete file text
$ var = In the file, say 'mine' comes in the 17th line (location is not available, but just giving examples) and I want to search after a pattern 'word' n (like 10) the word 'mine' 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 ( Warning The sub above is not designed to handle multiple matches in the single file above. Give it an exercise for the reader.
Comments
Post a Comment