Inputting Data
Data can be read from “standard in”.
- $name = <STDIN>
- The end-of-line character will be picked up as well as the text line.
- This could be from the keyboard or from a file that is directed to <STDIN>.
- ./my_script < data1
Inputting Data From a File
If you want to access a data file from your script, you first open the file.
- open(INFILE,”new_data”);
- You can read in the first line using <INFILE>
- Get rid of the “\n” at the end with the chomp() function.
Outputting Data to a File
If you want to access a data file for outputting from your script, you first open the file.
- open(OUTFILE,”>new_data”);
- You can write to the file using OUTFILE.
- print OUTFILE $data_line;
- Append using “>>” instead of “>”.
- See programs in perl/readdir1.