[Purdue-pm] Perl 6 feed operator
Mark Senn
mark at purdue.edu
Wed May 4 11:36:46 PDT 2016
Purdue Perl Mongers.
Below is some Perl 6 code implemented using feed operators and a simple
loop. I like the loop below better, Perl 6's dir() has a "test"
parameter to automatically grep file names but I don't know how to use
it for complicated tests yet and even if I did I wanted space to
document things line-by-line.
# Read entries from the current directory.
# Ignore entries that start with ".".
# Ignore non-files.
# Ignore non-writable files.
# Originally I had this
# dir()
# ==> grep({$_ !~~ /^\./})
# ==> grep({$_ ~~ :f})
# ==> grep({$_ ~~ :w})
# ==> @entry;
# but I like the following better.
my @entry = ();
for dir() # dir automatically ignores . and ..
{
(/^\./) and next; # ignore anything else that starts with a .
($_ ~~ :f) or next; # ignore non-files
($_ ~~ :w) or next; # ignore non-writiable files
push @entry, $_;
}
This is for a program called keep. Typing "keep filename" deletes
all other files in the current directory unless they start with a
. or are non-writable.
-mark
More information about the Purdue-pm
mailing list