#!/usr/bin/perl

#this is fh1.pl
open( MYFILE,">fh1txt" );
#for example of s.c, see the next
print MYFILE "hi there!\n";
print MYFILE "bye-bye\n";
close( MYFILE );


#diamond operator and s.c example
#this is fh2.pl 
open( TEST,"fh2txt" ) || die "can not open file!\n";
#open( TEST,"<fh2txt" ) || die "can not open file!\n";
$linecount =0;
while ($line = <TEST>){
	$linecount++;
}
close( TEST );
print "number of lines in the file: $linecount\n";



#below is not in the slides...

#summary of readin with Perl 
#ofcourse, you can use any file handle open in place of the STDIN

#1.
#execute the command like this:
#	perl xxxx.pl.
#then type in input 

#2. do:
#	perl xxxx.pl < echo somefile
#inside the code, do:
#	$a = <STDIN>; #to take one line in.
#or,
#	@a = <STDIN>; #to take all lines into array


#3. 
#the way we did in class.
#read all ine, one by one
#	while( $line  = <STDIN> ){ ... }
#or, save value in $_
#	while( <STDIN> ) { ... }

#4.
#really lazy way to do the same.
#using so called diamond operator...
#from the command line, do:
#	perl xxx.pl file1 file2 file3 
#inside the program, write:
#	while( <> ){ print $_ }     #this does what echo does

#5.
#same as 4. 
#from the command line, do:
#	perl xxx.pl 
#inside the program, write:
#	@ARGV = ("file1", "file2", "file3" );
#	while( <> ){ print $_ } 
