How about an example for output?

Links: Next Previous Up Top

# How about an example for `output`?

Here is a simple example to demonstrate how `output`, `push_output`, and `pop_output` work:

    output "Hello, world!\n";               # (Written to STDOUT by default)
    push_output('nul');                     # Push 'nul' ahead of STDOUT
    output "Hello, again!\n";               # (Discarded)
    push_output('file','foo.out');          # Push file 'foo.out' ahead of 'nul'
    output "Hello, again!\n";               # (Written to the file 'foo.out')
    pop_output;                             # Pop 'foo.out' and revert to 'nul'
    output "Hello, again!\n";               # (Discarded)
    push_output('string');                  # Push 'string' ahead of 'nul'
    output "Hello, ";                       # (Written to the string)
    output "again!\n";                      # (Also written to the string)
                                            # Pop the string "Hello, again!\n"
    $foo = pop_output;                      # and revert to 'nul'
    output "Hello, again!\n";               # (Discarded)
    pop_output;                             # Pop 'nul' and revert to STDOUT
    output "Hello, at last!\n";             # (Written to STDOUT)

Links: Next Previous Up Top