![]() With the data I have, this next line will return only Fred Flinstone: my = grep /F.*Flin/, pattern like this will get you Wilma Flinstone: my = grep /W.*F.*/, adding the letter i at the end of your regular expression will make your search case-insensitive, so this next regular expression pattern will also return Wilma Flinstone: my = grep /w.*f. There are other implementations of grep-like programs such as agrep, zipgrep, and grep-like functions in. In that example I'm searching for a very simple pattern (the string "Flin", with the letter "F" in uppercase, as shown), but of course with Perl and regular expressions these patterns can get much more complex. GNU grep is actually a combination of four different tools, each with its unique style of finding text: basic regular expressions, extended regular expressions, fixed strings, and Perl-style reg-ular expression. # create a list of all "people" array elements that match the pattern: If the only thing you could do was search for an exact piece of text in a file, regular expressions would be pretty useless. ![]() my = ( "Fred Flinstone", "Wilma Flinstone", "Barney Rubble", "Betty Rubble" ) In the source code below I create a list named and then I search that list using the grep function, telling grep the pattern I want to use for the search ( /Flin/) and giving it the list to search ( The grep function returns a list of all elements in my list that match this pattern, and I store those matches in a new list named After that I just print out the elements of the list to show that this worked. The grep() function in Perl used to extract any element from the given array which evaluates the true value for the given regular expression. Fortunately Perl is built for this type of work, and it's straightforward to (a) perform this search, and (b) put your search results in another list. ![]() A lot of times when you're using Perl you have a list (or array), and you need to search that list for all strings that match a certain regular expression pattern (or regex). USE flags for sys-apps/grep GNU regular expression matcher nls, Add Native Language Support (using gettext - GNU locale utilities) pcre, Add support for Perl. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |