Howdy again folks,
I can't tell you how invaluable everyone's input has been.
Here is my latest quandry.
I can read the file selected ten lines at a time, and I can advance
to the next 10 lines with
the return key (specifically stipulated in this assignment) but I am
trying to offer the user other options
like returning to the list of files and quitting.
in the following code I have tried == and eq. I'm thinking I should
chomp the input before checking if it's
an n or q (which is why I tried to kludge it with n\n and q\n, but
I'm not sure how to slip the chomp in without affecting the case
where I really need the newline.
sub page_control {
print "would you like to see the next ten lines of $file_list[$openme]?";
if (<STDIN> == "\n") {
& ten_line_file_reader;
}
elsif (<STDIN> == "n\n") {
& open_current_directory;
}
elsif (<STDIN> == "q\n") {
exit;
}
}
I will modify the prompt later, and any other tests later too (like
case insensitivity, or testing for garbage input)
Thanks in advance!!
CTP
###########################
# the current state of my script #
##########################
& open_current_directory;
sub open_current_directory {
opendir ( CURRDIR, '' ) || die "Can't open it!";
@file_list = readdir ( CURRDIR );
$i = 0;
foreach $file_name ( @file_list ) {
print "$i - $file_name\n";
$i++;
}
}
& which_file;
sub which_file {
print "Which file would you like to open?: ";
chomp ( $openme = <STDIN> );
print "I will open $file_list[$openme]\n";
open (THATFILE , $file_list[$openme] || die "can't open $file_list[$openme]");
}
& ten_line_file_reader;
sub ten_line_file_reader {
$j = 0;
while ($j < 10) {
$line = <THATFILE>;
print "$line\n";
$j++;
}
& page_control;
}
sub page_control {
print "would you like to see the next ten lines of $file_list[$openme]?";
if (<STDIN> == "\n") {
& ten_line_file_reader;
}
elsif (<STDIN> == "n\n") {
& open_current_directory;
}
elsif (<STDIN> == "q\n") {
exit;
}
}
close (THATFILE);
closedir (CURRDIR);