Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing some typos I spotted while reading the one-liners list. #16

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,43 +208,43 @@ Check if a number is a prime

Print the sum of all the fields on a line

perl6 -ne 'say [+] .split("\t")'
perl6 -ne 'say [+] .split("\t")' example.txt

Print the sum of all the fields on all lines

perl6 -e 'say [+] lines.split("\t")'
perl6 -e 'say [+] lines.split("\t")' example.txt

Shuffle all fields on a line

perl6 -ne '.split("\t").pick(*).join("\t").say'
perl6 -ne '.split("\t").pick(*).join("\t").say' example.txt

Find the lexically minimum element on a line

perl6 -ne '.split("\t").min.say'
perl6 -ne '.split("\t").min.say' example.txt

Find the lexically minimum element over all the lines

perl6 -e 'lines.split("\t").min.say'
perl6 -e 'lines.split("\t").min.say' example.txt

Find the lexically maximum element on a line

perl6 -ne '.split("\t").max.say'
perl6 -ne '.split("\t").max.say' example.txt

Find the lexically maximum element over all the lines

perl6 -e 'lines.split("\t").max.say'
perl6 -e 'lines.split("\t").max.say' example.txt

Find the numerically minimum element on a line

perl6 -ne '.split("\t")».Numeric.min.say'
perl6 -ne '.split("\t")».Numeric.min.say' example.txt

Find the numerically maximum element on a line

perl6 -ne '.split("\t")».Numeric.max.say'
perl6 -ne '.split("\t")».Numeric.max.say' example.txt

Replace each field with its absolute value

perl6 -ne '.split("\t").map(*.abs).join("\t").say'
perl6 -ne '.split("\t").map(*.abs).join("\t").say' example.txt

Find the total number of letters on each line

Expand All @@ -260,17 +260,17 @@ Find the total number of elements on each line, split on a comma

Find the total number of fields (words) on all lines

perl6 -e 'say lines.split("\t").elems' #fields
perl6 -e 'say lines.split("\t").elems' example.txt #fields
perl6 -e 'say lines.words.elems' example.txt #words

Print the total number of fields that match a pattern

perl6 -e 'say lines.split("\t").comb(/pattern/).elems' #fields
perl6 -e 'say lines.words.comb(/pattern/).elems' #words
perl6 -e 'say lines.split("\t").comb(/pattern/).elems' example.txt #fields
perl6 -e 'say lines.words.comb(/pattern/).elems' example.txt #words

Print the total number of lines that match a pattern

perl6 -e 'say lines.grep(/in/).elems'
perl6 -e 'say lines.grep(/in/).elems' example.txt

Print the number PI to n decimal places (e.g. 10)

Expand Down Expand Up @@ -322,7 +322,7 @@ Calculate greatest common divisor

perl6 -e 'say [gcd] @list_of_numbers'

Calculate GCM of numbers 20 and 35 using Euclid's algorithm
Calculate GCD of numbers 20 and 35 using Euclid's algorithm

perl6 -e 'say (20, 35, *%* ... 0)[*-2]'

Expand Down Expand Up @@ -659,7 +659,7 @@ Color conversion, HTML to RGB

Color conversion, RGB to HTML

echo "#ffff00" | perl6 -ne '.comb(/\w\w/).map({:16($_)}).say'
echo "(255 255 0)" | perl6 -ne 'my $out = "#"; for m:g/\d+/ -> $d { $out ~= sprintf("%02x", $d.Int);}; say $out;'

WWW
---
Expand Down