JavaScript
Standard (Screen) Output
To output XHTML code use:
document.write("text", variable, "(X)HTML tags", ...);
To output plain text, then wait for click on OK, use:
alert("text" + variable + "\n");
To output plain text, then wait for click on OK or Cancel, use:
confirm("Some question ... ");
Standard (Keyboard) Input
To output prompt, wait for click on OK, then return user input, use:
prompt("Text of prompt ... ", "default text");
PHP
Standard (Screen) Output
For output with default formats and without returning a value use one of these:
echo "one", "two";
echo ("one");
For output with default formats if you want to return 1 (success) or 0 (failure) use:
print "one";
For formatted output use:
printf
Standard (Keyboard) Input
Since PHP is a server-side technology, there is no need for keyboard input.
File Output
To open a file for writing output use:
$outfile_var = fopen("filename", "w");
To open a file for appending output use:
$outfile_var = fopen("filename", "a");
To write to an output file use:
$bytes_written = fwrite($file_var, $out_data);
File Input
To open a file for reading input:
$infile_var = fopen("filename", "r");
To read an entire textfile into a single string use:
$file_string = fread($infile_var, filesize("filename");
To read an entire textfile into an array of strings use:
$file_lines = file("filename");
To read a line of up to n-1 characters (not including the newline character) from a textfile, use:
$file_line = fgets($infile_var, 100);
To read a single character from a file, use:
$file_char = fgetc($infile_var);
File Input/Output
To open a file for input/output and position file pointer at file beginning, use one of the following.
For reading and writing an existing file, with any writing taking place wherever the last read (if any) stopped, use:
$inoutfile_var = fopen("filename", "r+");
For reading and writing a (possibly new) file, with any writing starting at the file beginning (thus overwriting any existing content), use:
$inoutfile_var = fopen("filename", "w+");
For reading and writing a (possibly new) file, with any writing taking place at the end of the file, use:
$inoutfile_var = fopen("filename", "a+");
Locking and Closing Files
To lock an open file use:
flock($file_var, 1|2|3);
To close an open file use:
fclose($file_var);
Perl
Standard (Screen) Output
For output with default formats use:
print
For formatted output use:
printf
Standard (Keyboard) Input
To read a line (including the newline character) from a textfile use:
<STDIN>
File Output
To open a file for writing output use:
open(OUTDAT, ">filename");
To open a file for appending output use:
open(OUTDAT, ">>filename");
To print to an output file use:
print OUTDAT "Some string ...";
File Input
To open a file for reading input:
open(INDAT, "<filename");
To read a line (including the newline character) from a textfile use:
$line = <INDAT>
To read a line from a binary file use:
read(INDAT, $buffer, length, buffer_offset);
File Input/Output
To open a file for both input and output use:
open(INOUTDAT, "+>filename");
To move the read/write "cursor" to a particular file location use:
seek(INOUTDAT, offset, 0|1|2);
Locking and Closing Files
To lock an open file use:
flock(FILE_HANDLE, LOCK_EX);
To close an open file use:
close(FILE_HANDLE);