{
    "mode": "perldoc",
    "parameter": "POE::Filter::Grep",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/POE%3A%3AFilter%3A%3AGrep/json",
    "generated": "2026-06-12T17:37:28Z",
    "synopsis": "#!perl\nuse POE qw(\nWheel::FollowTail\nFilter::Line Filter::Grep Filter::Stackable\n);\nPOE::Session->create(\ninlinestates => {\nstart => sub {\nmy $parseinputaslines = POE::Filter::Line->new();\nmy $selectsudologlines = POE::Filter::Grep->new(\nPut => sub { 1 },\nGet => sub {\nmy $input = shift;\nreturn $input =~ /sudo\\[\\d+\\]/i;\n},\n);\nmy $filterstack = POE::Filter::Stackable->new(\nFilters => [\n$parseinputaslines, # first on get, last on put\n$selectsudologlines, # first on put, last on get\n]\n);\n$[HEAP]{tailor} = POE::Wheel::FollowTail->new(\nFilename => \"/var/log/system.log\",\nInputEvent => \"gotlogline\",\nFilter => $filterstack,\n);\n},\ngotlogline => sub {\nprint \"Log: $[ARG0]\\n\";\n}\n}\n);\nPOE::Kernel->run();\nexit;",
    "sections": {
        "NAME": {
            "content": "POE::Filter::Grep - select or remove items based on simple rules\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "#!perl\n\nuse POE qw(\nWheel::FollowTail\nFilter::Line Filter::Grep Filter::Stackable\n);\n\nPOE::Session->create(\ninlinestates => {\nstart => sub {\nmy $parseinputaslines = POE::Filter::Line->new();\n\nmy $selectsudologlines = POE::Filter::Grep->new(\nPut => sub { 1 },\nGet => sub {\nmy $input = shift;\nreturn $input =~ /sudo\\[\\d+\\]/i;\n},\n);\n\nmy $filterstack = POE::Filter::Stackable->new(\nFilters => [\n$parseinputaslines, # first on get, last on put\n$selectsudologlines, # first on put, last on get\n]\n);\n\n$[HEAP]{tailor} = POE::Wheel::FollowTail->new(\nFilename => \"/var/log/system.log\",\nInputEvent => \"gotlogline\",\nFilter => $filterstack,\n);\n},\ngotlogline => sub {\nprint \"Log: $[ARG0]\\n\";\n}\n}\n);\n\nPOE::Kernel->run();\nexit;\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "POE::Filter::Grep selects or removes items based on simple tests. It may be used to filter\ninput, output, or both. This filter is named and modeled after Perl's built-in grep() function.\n\nPOE::Filter::Grep is designed to be combined with other filters through POE::Filter::Stackable.\nIn the \"SYNOPSIS\" example, a filter stack is created to parse logs as lines and remove all\nentries that don't pertain to a sudo process. (Or if your glass is half full, the stack only\nselects entries that DO mention sudo.)\n",
            "subsections": []
        },
        "PUBLIC FILTER METHODS": {
            "content": "In addition to the usual POE::Filter methods, POE::Filter::Grep also supports the following.\n\nnew",
            "subsections": [
                {
                    "name": "new",
                    "content": "parameter, or both a Put and a Get parameter. The values for Code, Put, and Get are code\nreferences that, when invoked, return true to select an item or false to reject it. A Code\nfunction will be used for both input and output, while Get and Put functions allow input and\noutput to be filtered in different ways. The item in question will be passed as the function's\nsole parameter.\n\nsub rejectbidoofs {\nmy $pokemon = shift;\nreturn 1 if $pokemon ne \"bidoof\";\nreturn;\n}\n\nmy $gottacatchnearlyall = POE::Filter::Grep->new(\nCode => \\&rejectbidoofs,\n);\n\nEnforce read-only behavior:\n\nmy $readonly = POE::Filter::Grep->new(\nGet => sub { 1 },\nPut => sub { 0 },\n);\n\nmodify"
                },
                {
                    "name": "modify",
                    "content": "parameters as new(), and it replaces the existing tests with new ones.\n\n# Don't give away our Dialgas.\n$gottacatchnearlyall->modify(\nGet => sub { 1 },\nPut => sub { return shift() ne \"dialga\" },\n);\n"
                }
            ]
        },
        "SEE ALSO": {
            "content": "POE::Filter for more information about filters in general.\n\nPOE::Filter::Stackable for more details on stacking filters.\n",
            "subsections": []
        },
        "BUGS": {
            "content": "None known.\n\nAUTHORS & COPYRIGHTS\nThe Grep filter was contributed by Dieter Pearcey. Documentation is provided by Rocco Caputo.\n\nPlease see the POE manpage for more information about authors and contributors.\n",
            "subsections": []
        }
    },
    "summary": "POE::Filter::Grep - select or remove items based on simple rules",
    "flags": [],
    "examples": [],
    "see_also": []
}