Section A.9. Functions and Filters


A.9. Functions and Filters

Functions and filters are defined with the same syntax and differ only in the way in which they operate.

A.9.1. Functions

 function <functionname> {     param($a = 3, $b = "sample")     <block> }

Functions can output objects into the pipeline by simply including them in the block body or explicitly using return.

Arguments passed to a function on the command line will be matched against variables defined by the param section, and the remainder will be available in the $args special array. If these arguments are included in a pipeline, all earlier pipeline stages will complete before the function is run, at which point any pipeline content will be available in the $input special array.

A.9.2. Filters

 filter <filtername> {     param($a = 3, $b = "sample")     <block> }

Like functions, filters output objects into the pipeline either by simply including the object in the block body or via the use of return. Again, if present, arguments are filled into the appropriate variables defined by the param statement, with the remainder ending up in the $args special argument. A filter is only used in a pipeline setting and will be invoked for every object. For each invocation, the special variable $_ will contain the pipeline object to process.




Monad Jumpstart
Monad Jumpstart
ISBN: N/A
EAN: N/A
Year: 2005
Pages: 117

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net