Skip to content

Instantly share code, notes, and snippets.

@b2gills

b2gills/bytes.p6 Secret

Last active Jul 10, 2018
Embed
What would you like to do?
Codegolf byte counter
#! /usr/bin/env perl6
for @*ARGS { $_ = '--stdin' when '-' }
#| find out the number of bytes
proto sub MAIN (|) {
# convert the result to a number and print it
try { say {*}.elems } or note $!.message;
}
#| the number of bytes in the clipboard
multi sub MAIN () {
xclip
}
#| the number of bytes in a file
multi sub MAIN ( Str $filename ){
$filename.IO.slurp( :!chomp, :bin )
}
#| the number of bytes on stdin
multi sub MAIN ( Bool :stdin($)! ){
$*IN.slurp(:bin)
}
sub xclip () {
run(«xclip -o», :out, :!err, :!in )
.out.slurp( :bin, :close )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment