Scroll to navigation

STAG-FILTER(1p) User Contributed Perl Documentation STAG-FILTER(1p)

NAME

stag-filter - filters a stag file (xml, itext, sxpr) for nodes of interest

SYNOPSIS

  stag-filter person -q name=fred file1.xml
  stag-filter person 'sub {shift->get_name =~ /^A*/}' file1.xml
  stag-filter -p My::Foo -w sxpr record 'sub{..}' file2

USAGE

  stag-filter [-p|parser PARSER] [-w|writer WRITER] NODE -q tag=val FILE
  stag-filter [-p|parser PARSER] [-w|writer WRITER] NODE SUB FILE
  stag-filter [-p|parser PARSER] [-w|writer WRITER]  NODE -f PERLFILE FILE

DESCRIPTION

parsers an input file using the specified parser (which may be a built in stag parser, such as xml) and filters the resulting stag tree according to a user-supplied subroutine, writing out only the nodes/elements that pass the test.

the parser is event based, so it should be able to handle large files (although if the node you parse is large, it will take up more memory)

ARGUMENTS

FORMAT is one of xml, sxpr or itext, or the name of a perl module

xml assumed as default

FORMAT is one of xml, sxpr or itext, or the name of a perl module
prints the number of nodes that pass the test
a file containing a perl subroutine (in place of the SUB argument)
filters based on the field TAG

other operators can be used too - eg <, <=, etc

multiple q arguments can be passed in

for more complex operations, pass in your own subroutine, see below

a perl subroutine. this subroutine is evaluated evry 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

the name of the node/element we are filtering on
the file to be parser. If no parser option is supplied, this is assumed to a 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

2022-06-12 perl v5.34.0