STAG-GREP(1p)
π STAG-GREP π
okay bestie, welcome to stag-grep, a lil section 1p situation from the User Contributed Perl Documentation corner of the universe, and it is exactly the glow-up your messy stag files have been begging for β¨
πΈ NAME πΈ
stag-grep β filters a stag file (xml, itext, sxpr) for nodes of interest π¦
fr fr that's the whole vibe: you point it at a stag file, you tell it which nodes you care about, and it hands you back only those. no cap.
β¨ SYNOPSIS β¨
stag-grep person -q name=fred file1.xml
stag-grep person 'sub {shift->get_name =~ /^A*/}' file1.xml
stag-grep -p My::Foo -w sxpr record 'sub{..}' file2
likeβ¦ look at her. three whole moods. π
π USAGE π
stag-grep [-p|parser PARSER] [-w|writer WRITER] NODE -q tag=val FILE
stag-grep [-p|parser PARSER] [-w|writer WRITER] NODE SUB FILE
stag-grep [-p|parser PARSER] [-w|writer WRITER] NODE -f PERLFILE FILE
pick your fighter: query mode, sub mode, or perlfile mode. all iconic. π
π DESCRIPTION π
so basically it parses an input file using whatever parser you told it to use β could be a built-in stag parser like xml, could be something fancier β and then it filters the resulting stag tree according to a subroutine you supply. it writes out only the nodes/elements that pass the test. that's it. that's the whole job. and it ate. π₯
and here's the part that's lowkey genius: the parser is event based, so it should be able to handle large files π«Ά (although β heads up bestie β if the node you parse is large, it will take up more memory. it's giving "big node, big feelings", so just know that going in π)
π ARGUMENTS π
-p|parser FORMATβ FORMAT is one ofxml,sxproritext, or the name of a perl module.xmlis assumed as default π£-w|writer FORMATβ FORMAT is one ofxml,sxproritext, or the name of a perl module βοΈ-c|countβ prints the number of nodes that pass the test π’ (not the nodes themselves, just the headcount. it's giving attendance sheet.)-filterfile|fβ a file containing a perl subroutine (in place of theSUBargument) π-q|query TAG1=VAL1-q|query TAG2=VAL2...-q|query TAGN=VALNβ filters based on the fieldTAGπ- other operators can be used too β eg
<,<=, etc βοΈ - multiple
qarguments can be passed in (stack 'em up, queen) π₯ - for more complex operations, pass in your own subroutine, see below π
- other operators can be used too β eg
SUBβ a perl subroutine. this subroutine is evaluated every timeNODEis encountered β the stag object forNODEis passed into the subroutine π§- if the subroutine passes, the node will be passed to the writer for display π₯οΈ
NODEβ the name of the node/element we are filtering on π―FILEβ the file to be parsed. If no parser option is supplied, this is assumed to be a stag compatible syntax (xml,sxproritext); otherwise you should parse in a parser name or a parser module that throws stag events π
π¦ SEE ALSO π¦
Data::Stagβ the whole ecosystem, go say hi π
perl v5.34.0 Β· 2022-06-12
and that's the tea, bestie π this page was served to you fresh from perl v5.34.0, dated 2022-06-12, straight out of the User Contributed Perl Documentation collection π go filter something gorgeous, you've got this. mwah. πβ¨π
π¦ where this page comes from
- debian bookworm: libdata-stag-perl 0.14-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libdata-stag-perl 0.14-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libdata-stag-perl 0.14-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu questing: libdata-stag-perl 0.14-3
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms