Permalink
Browse files

Use $*SPEC.catdir for platform independent path names

  • Loading branch information...
paultcochrane committed May 18, 2015
1 parent c71e660 commit 4b9b8c28fd4ec118468503da3017ec0085d4177b
@@ -25,7 +25,7 @@
my $i = 1;
constant A = 'A'.ord - 1;
my $names-file = $*PROGRAM_NAME.IO.dirname ~ "/names.txt";
my $names-file = $*SPEC.catdir($*PROGRAM_NAME.IO.dirname, "names.txt");
my $data = slurp $names-file;
my @names = sort $data.subst('"', '', :g).split(',');
say [+] gather
@@ -42,7 +42,7 @@
use NativeCall;
sub factors(int $n) returns int is native($*PROGRAM_NAME.IO.dirname ~ '/prob047-gerdr') { * }
sub factors(int $n) returns int is native($*SPEC.catdir($*PROGRAM_NAME.IO.dirname, 'prob047-gerdr')) { * }
sub MAIN(Int $N = 4) {
my int $n = 2;
@@ -228,7 +228,7 @@
sub MAIN(Bool :$verbose = False,
Bool :$run-tests = False,
:$file = $*PROGRAM_NAME.IO.dirname ~ '/poker.txt',
:$file = $*SPEC.catdir($*PROGRAM_NAME.IO.dirname, 'poker.txt'),
:$lines = Inf, # read only X lines from file
) {
die "'$file' is missing" unless $file.IO.e ;
@@ -86,7 +86,7 @@ sub infix:<XOR>(@cipher, @password) {
}
sub MAIN(Bool :$verbose = False,
:$file = $*PROGRAM_NAME.IO.dirname ~ '/cipher.txt',
:$file = $*SPEC.catdir($*PROGRAM_NAME.IO.dirname, 'cipher.txt'),
:$word = @common-words[0],
:$pass is copy) {
die "'$file' is missing" unless $file.IO.e ;
@@ -34,7 +34,7 @@
=end pod
my $triangle = slurp($*PROGRAM_NAME.IO.dirname ~ '/triangle.txt');
my $triangle = slurp($*SPEC.catdir($*PROGRAM_NAME.IO.dirname, '/triangle.txt'));
my @lines = string-to-array($triangle).reverse;
# reduce the triangle by adding up the lines until only one line with one
@@ -29,7 +29,7 @@
my @m;
my $matrix-file = $*PROGRAM_NAME.IO.dirname ~ '/matrix.txt';
my $matrix-file = $*SPEC.catdir($*PROGRAM_NAME.IO.dirname, 'matrix.txt');
my $f = open $matrix-file or die "Can't open file for reading: $!";
for $f.lines {
@m.push: [ .comb(/\d+/) ];
@@ -23,8 +23,7 @@
use LWP::Simple;
sub MAIN(Str $id = "Q5SLP9") {
my $base-path = $*PROGRAM_NAME.IO.dirname;
my $id-fname = $base-path ~ "/$id.txt";
my $id-fname = $*SPEC.catdir($*PROGRAM_NAME.IO.dirname, "$id.txt");
my $input = $id-fname.IO.e
?? $id-fname.IO.slurp
!! LWP::Simple.get(qq{http://www.uniprot.org/uniprot/$id.txt});
@@ -29,7 +29,7 @@
use NativeCall;
sub lcsq(Str $, Str $ --> Str) is native($*PROGRAM_NAME.IO.dirname ~ '/lcsq') {*}
sub lcsq(Str $, Str $ --> Str) is native($*SPEC.catdir($*PROGRAM_NAME.IO.dirname, 'lcsq')) {*}
my $default-input = q:to/END/;
>Rosalind_23
@@ -38,7 +38,7 @@ ($input-file = Nil)
my $N-glycosylation = rx / N <-[P]> <[ST]> <-[P]> /;
my $base-path = $*PROGRAM_NAME.IO.dirname;
for @input -> $id {
my $fasta-name = $base-path ~ "/$id.fasta";
my $fasta-name = $*SPEC.catdir($base-path, "$id.fasta");
my $fasta = $fasta-name.IO.e
?? $fasta-name.IO.slurp
!! qqx{wget -O - -q "http://www.uniprot.org/uniprot/$id.fasta"};
@@ -40,8 +40,10 @@
sub MAIN($input-file = Nil) {
my $input = $input-file ?? $input-file.IO.slurp !! $default-input;
my $mass-table-path = $*PROGRAM_NAME.IO.dirname;
my %mass-table = slurp($mass-table-path ~ "/monoisotopic-mass-table.txt").words;
my $mass-table-file = $*SPEC.catdir($*PROGRAM_NAME.IO.dirname,
"monoisotopic-mass-table.txt");
my %mass-table = slurp($mass-table-file).words;
my @L = sort $input.lines;
my %invert-mass-table = %mass-table.invert.hash;
@@ -44,7 +44,7 @@ Expected output
=end pod
sub MAIN($input-file = $*PROGRAM_NAME.IO.dirname ~ "/k-nucleotide.input") {
sub MAIN($input-file = $*SPEC.catdir($*PROGRAM_NAME.IO.dirname, "k-nucleotide.input")) {
my $fh = open $input-file.IO;
# Read FASTA file and extract DNA sequence THREE.
@@ -30,7 +30,7 @@ Expected output
=end pod
sub MAIN($input-file = $*PROGRAM_NAME.IO.dirname ~ "/regex-dna.input") {
sub MAIN($input-file = $*SPEC.catdir($*PROGRAM_NAME.IO.dirname, "regex-dna.input")) {
my $input = $input-file.IO.slurp;
my $data = $input.lines.grep({ $_ !~~ /^ \>/}).join.lc;
@@ -187,7 +187,7 @@ Expected output
my %trans = 'wsatugcyrkmbdhvnATUGCYRKMBDHVN'.comb Z=>
'WSTAACGRYMKVHDBNTAACGRYMKVHDBN'.comb;
sub MAIN($input-file = $*PROGRAM_NAME.IO.dirname ~ "/revcomp.input") {
sub MAIN($input-file = $*SPEC.catdir($*PROGRAM_NAME.IO.dirname, "revcomp.input")) {
my ($desc, @seq);
for $input-file.IO.lines {
@@ -188,7 +188,7 @@ Expected output
=end pod
sub MAIN($input-file = $*PROGRAM_NAME.IO.dirname ~ "/revcomp.input") {
sub MAIN($input-file = $*SPEC.catdir($*PROGRAM_NAME.IO.dirname, "revcomp.input")) {
my ($desc,$seq) = ('','');
my $input = open $input-file;
while $input.get -> $line {
@@ -113,7 +113,7 @@
=end pod
sub MAIN(Bool :$verbose = False) {
my $input-file = $*PROGRAM_NAME.IO.dirname ~ "/wordlist.txt";
my $input-file = $*SPEC.catdir($*PROGRAM_NAME.IO.dirname, "wordlist.txt");
my %dict = ( ($input-file.IO.slurp.split("\n").grep: {.chars == 7}) X 1);
my %digits = (
@@ -65,7 +65,7 @@
=end pod
my $input-file = $*PROGRAM_NAME.IO.dirname ~ "/skaters.txt";
my $input-file = $*SPEC.catdir($*PROGRAM_NAME.IO.dirname, "skaters.txt");
my @lines = slurp($input-file).split("\n");
my %skaters ;
@@ -148,7 +148,7 @@
sub MAIN(Str :$pw = "", Bool :$verbose = False) {
my $password = $pw || prompt("Enter password to test: ");
my $input-file = $*PROGRAM_NAME.IO.dirname ~ "/wordlist.txt";
my $input-file = $*SPEC.catdir($*PROGRAM_NAME.IO.dirname, "wordlist.txt");
my %dict = ( ($input-file.IO.slurp.split("\n").grep: {.chars > 6}) X 1);
say "Testing strength of password '$password'" if $verbose;
@@ -37,7 +37,7 @@
my $run-dir = $*PROGRAM_NAME.IO.dirname;
my @files = dir($run-dir).sort;
my $output = $run-dir ~ '/newfile.txt';
my $output = $*SPEC.catdir($run-dir, 'newfile.txt');
$output.IO.unlink if $output.IO.e;
# only select .txt files required for this event
@@ -46,7 +46,7 @@
=end pod
my $coffee-list = $*PROGRAM_NAME.IO.dirname ~ '/coffee.txt';
my $coffee-list = $*SPEC.catdir($*PROGRAM_NAME.IO.dirname, 'coffee.txt');
my $lines = slurp($coffee-list).chomp;
my %order;
for $lines.split(/\n/) {
@@ -48,7 +48,7 @@
our %count_for;
sub MAIN(Str $orders = $*PROGRAM_NAME.IO.dirname ~ '/coffee.txt') {
sub MAIN(Str $orders = $*SPEC.catdir($*PROGRAM_NAME.IO.dirname, 'coffee.txt')) {
# get the data
my @contents = $orders.IO.lines;

0 comments on commit 4b9b8c2

Please sign in to comment.