-
-
Save b2gills/93d1e2aa6583b95315b2 to your computer and use it in GitHub Desktop.
Codegolf byte counter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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