Skip to content

Instantly share code, notes, and snippets.

@Tux
Created February 13, 2015 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tux/4dbf087e5718a1dfee7f to your computer and use it in GitHub Desktop.
Save Tux/4dbf087e5718a1dfee7f to your computer and use it in GitHub Desktop.
return/exit/die after else. YUCK!
IO.pm
sub MAKE-ABSOLUTE-PATH($path,$abspath) {
if $path.ord == 47 { # 4x faster substr($path,0,1) eq "/"
return $path;
}
elsif substr($path,1,1) eq ':' { # assume C: something
if substr($path,2,1) eq "/" { # assume C:/ like prefix
return $path;
}
elsif substr($abspath,0,2) ne substr($path,0,2) {
die "Can not set relative dir from different roots";
}
else {
return $abspath ~ substr($path,2);
}
}
else { # assume relative path
return $abspath ~ $path;
}
}
=>
sub MAKE-ABSOLUTE-PATH($path,$abspath) {
$path.ord == 47 and # 4x faster substr($path,0,1) eq "/"
return $path;
substr($path,1,1) ne ':' and # C: like prefix?
return $abspath ~ $path; # assume relative path
# assume C: something
substr($path,2,1) eq "/" and # assume C:/ like prefix
return $path;
substr($abspath,0,2) ne substr($path,0,2) and
die "Can not set relative dir from different roots";
return $abspath ~ substr($path,2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment