Skip to content

Commit

Permalink
three LHF file contents examples
Browse files Browse the repository at this point in the history
  • Loading branch information
stmuk committed Aug 31, 2015
1 parent 45bcffa commit e83ca50
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
17 changes: 17 additions & 0 deletions categories/cookbook/08-file-contents/08-02-count-lines.pl
@@ -0,0 +1,17 @@
use v6;

=begin pod
=TITLE Count File Lines
=AUTHOR stmuk
You want to count the number of lines in a file
=end pod

my @lines = $*PROGRAM-NAME.IO.lines;

say @lines.elems;

# vim: expandtab shiftwidth=4 ft=perl6
20 changes: 20 additions & 0 deletions categories/cookbook/08-file-contents/08-03-process-words.pl
@@ -0,0 +1,20 @@
use v6;

=begin pod
=TITLE Process every word in a file
=AUTHOR stmuk
You want to process every word in a file
=end pod

my @words = $*PROGRAM-NAME.IO.words;

for @words -> $word {
dd $word;
}


# vim: expandtab shiftwidth=4 ft=perl6
@@ -0,0 +1,20 @@
use v6;

=begin pod
=TITLE Read file lines backwards
=AUTHOR stmuk
You want to read file lines backwards
=end pod

my @lines = $*PROGRAM-NAME.IO.lines;
@lines .= reverse;

for @lines -> $line {
dd $line;
}

# vim: expandtab shiftwidth=4 ft=perl6

0 comments on commit e83ca50

Please sign in to comment.