Skip to content

Instantly share code, notes, and snippets.

@b2gills

b2gills/bytes.p6 Secret

Last active July 10, 2018 06:07
Show Gist options
  • Save b2gills/93d1e2aa6583b95315b2 to your computer and use it in GitHub Desktop.
Save b2gills/93d1e2aa6583b95315b2 to your computer and use it in GitHub Desktop.
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