Tedious,
and Well Covered Elsewhere
• Getting a command line
(Terminal, CMD, xterm...)
• Current directory
(and Windows "Drive Letter")
• Text Editor
(not Word Processor!)
• wsl --install
Slide 18
Slide 18 text
Very Useful,
but Not Covered This Year
• Command-line Perl
• -e and -E
• -n and -p
• -a and -F
• -l and -0777
• BEGIN and END
Slide 19
Slide 19 text
perl -0777 -wnE 's{\rMSH}{\nMSH}g;
s{\r\z}{\n}; my @L = split "\n";
s{\A.+\r(OBR)}{$1} for @L; s{\r.+\z}{}
for @L; tr{|}{\t} for @L; for (@L) {my @F
= split "\t"; $ARGV =~ /lab_(\d\d\d\d)-/
or warn; say "$1\t$F[20]"}' lab_*.txt
> ../assessions.txt
Slide 20
Slide 20 text
Loosely Related
• CLI : Command Line Interface
• git status, git commit...
• ls [-ABCFGHLOPRSTUW@abcdefghiklmnopqrstuwx1]
__END__
Adapted from original one-liner:
perl -wpE 'if ($. != 1) {s/^"\d+",// or die}' v_o.csv | sort | uniq -c | sort -nr
Slide 77
Slide 77 text
How it works
• open my $fh, '<', 'myfile.txt';
• Magic cookie
•
•
•
•
Slide 78
Slide 78 text
No content
Slide 79
Slide 79 text
How it works
• open my $fh, '<', 'myfile.txt';
• Magic cookie
• 0,1,2
• STDIN, STDOUT, STDERR
• $*IN, $*OUT, $*ERR
• Sane defaults, invention of STDERR
Slide 80
Slide 80 text
Peter Piper Processed a Plethora of
Programs
Slide 81
Slide 81 text
Peter Piper Processed a Plethora of
Programs, in Parallel !
Slide 82
Slide 82 text
Peter Piper Processed a Plethora of
Programs, in Parallel !
seq
Slide 83
Slide 83 text
Peter Piper Processed a Plethora of
Programs, in Parallel !
seq 1000000000
Slide 84
Slide 84 text
Peter Piper Processed a Plethora of
Programs, in Parallel !
seq 1000000000 | cut -c 1
Slide 85
Slide 85 text
Peter Piper Processed a Plethora of
Programs, in Parallel !
seq 1000000000 | cut -c 1 | uniq
Slide 86
Slide 86 text
Peter Piper Processed a Plethora of
Programs, in Parallel !
seq 1000000000 | cut -c 1 | uniq
Slide 87
Slide 87 text
Now You!
Slide 88
Slide 88 text
use autodie;
my $input_path = './name1_to_edit_by_hand.txt';
my $output_path = './name2_to_edit_by_hand.txt';
open my $fh_in, '<', $input_path;
open my $fh_out, '>', $output_path;
while ( my $line = <$fh_in> ) {
chomp $line;
my $output = do_something_with($line);
say {$out_fh} $output;
}
Slide 89
Slide 89 text
use autodie;
my $input_path = './name1_to_edit_by_hand.txt';
my $output_path = './name2_to_edit_by_hand.txt';
open my $fh_in, '<', $input_path;
open my $fh_out, '>', $output_path;
while ( my $line = <$fh_in> ) {
chomp $line;
my $output = do_something_with($line);
say {$out_fh} $output;
}
Slide 90
Slide 90 text
use autodie;
my $input_path = './name1_to_edit_by_hand.txt';
my $output_path = './name2_to_edit_by_hand.txt';
open my $fh_in, '<', $input_path;
open my $fh_out, '>', $output_path;
while ( my $line = <$fh_in> ) {
chomp $line;
my $output = do_something_with($line);
say {$out_fh} $output;
}
Slide 91
Slide 91 text
while (<>) {
chomp;
say do_something_with($_);
}
prog ./name1_to_edit_by_hand.txt >./name2_to_edit_by_hand.txt
Slide 92
Slide 92 text
#!/usr/bin/env python3
import fileinput
for line in fileinput.input():
line = line.rstrip('\r\n')
print(">>", line, "<<")
https://docs.python.org/3/library/fileinput.html
#!/usr/bin/env perl
use 5.36.0;
while (<>) {
chomp;
say ">> $_ <<";
}
https://perldoc.perl.org/perlop#I/O-Operators
#!/usr/bin/env raku
use v6;
for lines() {
say ">> $_ <<";
}
https://docs.raku.org/type/IO::CatHandle
Slide 93
Slide 93 text
#!/usr/bin/env python3
import fileinput
for line in fileinput.input():
line = line.rstrip('\r\n')
print(">>", line, "<<")
https://docs.python.org/3/library/fileinput.html
#!/usr/bin/env perl
use 5.36.0;
while (<>) {
chomp;
say ">> $_ <<";
}
https://perldoc.perl.org/perlop#I/O-Operators
#!/usr/bin/env raku
use v6;
for lines() {
say ">> $_ <<";
}
https://docs.raku.org/type/IO::CatHandle
Slide 94
Slide 94 text
#!/usr/bin/env python3
import fileinput
for line in fileinput.input():
line = line.rstrip('\r\n')
print(">>", line, "<<")
https://docs.python.org/3/library/fileinput.html
#!/usr/bin/env perl
use 5.36.0;
while (<>) {
chomp;
say ">> $_ <<";
}
https://perldoc.perl.org/perlop#I/O-Operators
#!/usr/bin/env raku
use v6;
for lines() {
say ">> $_ <<";
}
https://docs.raku.org/type/IO::CatHandle
Slide 95
Slide 95 text
#!/usr/bin/env python3
import fileinput
for line in fileinput.input():
line = line.rstrip('\r\n')
print(">>", line, "<<")
https://docs.python.org/3/library/fileinput.html
#!/usr/bin/env perl
use 5.36.0;
while (<>) {
chomp;
say ">> $_ <<";
}
https://perldoc.perl.org/perlop#I/O-Operators
#!/usr/bin/env raku
use v6;
for lines() {
say ">> $_ <<";
}
https://docs.raku.org/type/IO::CatHandle
Slide 96
Slide 96 text
# XXX Remove after testing !!!
my $default_file = 'C:/path/to/trimmed.dat';
push @ARGV, $default_file if not @ARGV;
Slide 97
Slide 97 text
# XXX Remove after testing !!!
my $default_file = 'C:/path/to/trimmed.dat';
push @ARGV, $default_file if not @ARGV;
@ARGV ||= $default_file;
Slide 98
Slide 98 text
# XXX Remove after testing !!!
my $default_file = 'C:/path/to/trimmed.dat';
push @ARGV, $default_file if not @ARGV;
@ARGV ||= $default_file; # Fails sometimes
Slide 99
Slide 99 text
Further Reading
• https://utcc.utoronto.ca/~cks/space/blog/python/
ProgramFilterVsWrapper
Programs as wrappers versus filters of other
programs
• http://catb.org/~esr/writings/taoup/html/
ch01s06.html
Basics of the Unix Philosophy
Slide 100
Slide 100 text
Sched
• https://utcc.utoronto.ca/~cks/space/blog/python/
ProgramFilterVsWrapper
Programs as wrappers versus filters of other
programs
• http://catb.org/~esr/writings/taoup/html/
ch01s06.html
Basics of the Unix Philosophy
Slide 101
Slide 101 text
Q & A
Slide 102
Slide 102 text
Command-line Filters: Time to Shine
PLEASE DOWNLOAD THESE SLIDES!
http://speakerdeck.com/util
<<<
>>>
>>>
<<<
Copyright Information:
This Talk
This work is licensed under a Creative
Commons Attribution 4.0 International License.
CC BY
https://creativecommons.org/licenses/by/4.0/
(email me for the original Apple Keynote .key file)
Slide 107
Slide 107 text
History
• v 0.98 2022-06-02
Presented incomplete version to Atlanta
Perlmongers
• v 1.00 2022-06-24
Presented final version to The Perl and Raku
Conference in Houston, TX, USA