File input/output: Difference between revisions

Line 238:
==[[Perl]]==
'''Interpreter:''' [[Perl]] 5.8.8
#!/usr/bin/perl -w
open INPUTmy $fh_in, '<', 'input.txt' or die "could not open <input.txt> for reading: $!";
open OUTPUTmy $fh_out, "'>', 'output.txt";' #or Onedie '>'"could overwritesnot file,open Two '<output.txt>>' appendsfor towriting: file.$!";
# '>' overwrites file, '>>' appends to file, just like in the shell
while ( <INPUT$fh_in> ) {
print OUTPUT$fh_out $_;
};
close $fh_in;
close $fh_out;
 
Perl has also a powerful mechanism in conjunction with opening files called IO disciplines. It allows you to automatically apply chainable transformations on the input and output. Mangling newlines, gzip (de)compression and character encoding are the most used examples.
 
==[[PHP]]==
Anonymous user