1 =head1 Advanced Lines Example
3 This is an advanced example.
5 It uses a file stream (Stream::ParrotIO) that is processed linewise with
6 Stream::Lines. A counter stream creates line numbers, both are combined to
7 one stream and then dumped.
11 When updating this file, be sure to verify L<t/examples/streams.t>, as its
12 tests rely on the content of this file.
20 Opens this file (or the one specified at the command line) and creates a lines
21 stream for it. Then it combines the stream with a stream providing line numbers.
34 # get the name of the file to open
35 name = "examples/streams/FileLines.pir"
37 if argc < 2 goto NO_NAME
41 load_bytecode 'Stream/ParrotIO.pbc'
42 load_bytecode 'Stream/Lines.pbc'
43 load_bytecode 'Stream/Sub.pbc'
44 load_bytecode 'Stream/Combiner.pbc'
46 # create a file stream
47 file = new ['Stream'; 'ParrotIO']
48 file."open"( name, 'r' )
50 # process it one line per read
51 lines = new ['Stream'; 'Lines']
55 counter = new ['Stream'; 'Sub']
56 .const 'Sub' temp = "_counter"
59 # combine the counter and the file's lines
60 combiner = new ['Stream'; 'Combiner']
61 assign combiner, counter
62 assign combiner, lines
72 This sub is the source of the counter stream. It just endlessly writes
73 line numbers followed by a space to its stream.
84 array = new 'ResizablePMCArray'
89 sprintf str, "%5d ", array
98 Jens Rieks E<lt>parrot at jensbeimsurfen dot deE<gt> is the author
100 Please send patches and suggestions to the Perl 6 Internals mailing list.
104 Copyright (C) 2004-2009, Parrot Foundation.
112 # vim: expandtab shiftwidth=4 ft=pir: