Skip to content

Instantly share code, notes, and snippets.

@loverdos
Created March 7, 2012 13:35
Show Gist options
  • Save loverdos/1993160 to your computer and use it in GitHub Desktop.
Save loverdos/1993160 to your computer and use it in GitHub Desktop.
Show PATH elements in separate lines
(* My second Ocaml program ever *)
(* *)
(* @author Christos KK Loverdos *)
open Str
(* Version 1 *)
(* ========= *)
(* let () = *)
(* let colon_re = Str.regexp ":" *)
(* and path = Sys.getenv "PATH" in *)
(* let paths = Str.split colon_re path in *)
(* let print s = *)
(* print_string s; *)
(* print_newline (); *)
(* in *)
(* List.iter print paths *)
(* Version 2 *)
(* ========= *)
(* List.iter (print_endline) (Str.split (Str.regexp ":") (Sys.getenv "PATH")) *)
(* Version 3 *)
(* ========= *)
let (|>) x f = f x
let () =
Sys.getenv "PATH" |> Str.split (Str.regexp ":") |> List.iter print_endline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment