STAG-GREP(1p)

πŸ“¦
version 0.14 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu questing

πŸ’– 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 of xml, sxpr or itext, or the name of a perl module. xml is assumed as default 🐣
  • -w|writer FORMAT β€” FORMAT is one of xml, sxpr or itext, 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 the SUB argument) πŸ“„
  • -q|query TAG1=VAL1 -q|query TAG2=VAL2 ... -q|query TAGN=VALN β€” filters based on the field TAG πŸ”
    • other operators can be used too β€” eg <, <=, etc βš–οΈ
    • multiple q arguments can be passed in (stack 'em up, queen) πŸ₯ž
    • for more complex operations, pass in your own subroutine, see below πŸ‘‡
  • SUB β€” a perl subroutine. this subroutine is evaluated every time NODE is encountered β€” the stag object for NODE is 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, sxpr or itext); 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