Input and Output
Input and output in Perl happens (primarily) through filehandles, which vaguely resemble FILE * in C. Filehandles are not declared like other variables; they are created using the open call and have no special punctuation:
open( HANDLE, " ; # All open filehandles should be closed close( HANDLE ); Passing handles between subroutines, and having them work fully the way you expect, usually involves horrible hacks. Here is some voodoo that happens to work:
sub copy_line { my ($in, $out) = @_; my $line = <$in>; print $out $line; } open( IN, " file2" ) or die "Error: $!"; copy_line(IN, OUT); close( IN ); close( OUT ); If you don't want to just read one line at a time, there are library functions that give you more flexibility:
# Character by character I/O my $char = getc( HANDLE ); # Read specified number of bytes read( HANDLE, $bytes, 100 );