#!/usr/bin/perl -w

print "Please enter a file to read: ";

$ans = <STDIN>; chomp($ans);
    
# Make user tell us what file to read.

$file_path = $ans;

    # If true
    	if(open(FH, $file_path)) 
    	{
    # While still receiving data
    	 while($file_buffer = <FH>)
    {
    $i++;
    	if($i == 10) 
    	{
    	 system("Pause");
    $i=0;
    }
    	print $file_buffer;
    	 }
    close(FH);

# We can close the file here
# since we just got off the while loop
# it signifies that were done reading...

    }
    else
    	{
    	  die "Cannot open file; $i\n";
    	}

# close(FH); Can close it here as well
# instead of up there, same thing...



# Perl tries to interact smoothly with the operating system.
# The top layer of this interaction is file handling.
# This example opens a file. The variable IN is a filehandle

open(IN, ">test");

print IN "In we go";

close(IN);


# Preceding the filename is a redirection character. 

> opens for output 
>> appends 
< opens for input 
| opens a pipe 

# By default, Perl reads data files one line at a time.
# There is a special syntax for reading the next line: 

$filename = $ARGV[0];       #get command line argument

open(IN, "<$filename");

$line = <IN>;               #read the first line
print $line;

while(<IN>) {               #loop as long as not EOF
print $_;                   #loop variable -- contains current line
}

# There are many short cut features in Perl. In particular,
# there are a host 'special variables' like $_. 
