# -*- pike -*- # hello world # print a simple string on stdout return "Hello World" # argv # access command line parameters (no segmentation fault accepted, nor silent exception, so some languages must explicitly check the presence of the argument) return argv[0] # env # access environment variable return env->HOME # test file exists # return exit code error (non zero) if a file does not exist return !file_stat("/etc/mtab") # test file readable # return exit code error (non zero) if a file is not readable return !!catch(Stdio.File("/etc/mtab")) # formatting # print integers in a simple formatted string int a=1, b=2; write("%d + %d = %d", a, b, a + b); # system # call an external program and check the return value Process.system("false") && werror("false failed\n"); Process.system("echo done"); # sed in place # remove #-comments from a file (modifying the file, i.e. in place) int main(int n, array args) { array r = ({}); foreach(Stdio.read_file(args[1]) / "\n", string x) { sscanf(x, "%s#", x); r += ({x}); } Stdio.write_file(args[1], r*"\n"); } # compile what must be # find and compile .c files into .o when the .o is old or absent int main() { object i = Filesystem.Traversion("."); foreach (i; string d; string c) { if (!has_suffix(c, ".c")) continue; c = d+c; string o = c; o[-1] = 'o'; object s = file_stat(o); if (s && i->stat()->mtime < s->mtime) continue; write("compiling %s to %s\n", c, o); Process.Process(({"gcc", "-c", "-o", o, c}))->wait(); } }