Can someone tell me what is going wrong with my conditional hook tests as marked below?
#!/usr/bin/perl -w
use warnings;
#this program's specification is on page 167
#in the Llama book under exercise 1
my ($source, $go, $dest, $expression, $over);
print"\$over = 1" if($ARGV[0] eq "-o");
until($go){
print "Please enter a source filename: ";
chomp ($source = <STDIN>);
$go = ($over ? 1 : &filep($source, 0));# Here
}
$go = 0;
until($go){
print "\nPlease enter a destination filename: ";
chomp ($dest = <STDIN>);
$go = ($over ? 1 : &filep($dest, 1));# And here
}
die "ERROR: Cannot read and write to same file.\n" if($source eq $dest);
if(!$over){
print "\n\t",'*' x 20,"\n\Uwarning this will overwrite your destination\E".
" \Ufile\E\n\t",'*' x 20,"\nWould you like to continue?(y/n)\n";
chomp($_ = <STDIN>);
die "This program has terminated by user command\n" if(/n/);
}
print"\nThis program will now accept a single Regular Expression".
" this expression, if entered correctly will copy all matching".
" data from $source to $dest.\nPlease enter a valid Perl style".
" regular expression:\n(default method = \"case-insensitive\"".
" with delimiter ommission and \\1 being entire match)\n";
chomp($expression = <STDIN>);
open INFILE, "<$source" or die "Unable to open $source for read: $!";
open OUTFILE, ">$dest" or die "Unable to open $dest for write: $!";
while (<INFILE>){
if(/($expression)/i){
print OUTFILE "$_\n";
}
}
close INFILE, OUTFILE;
print "\nDone.\n";
sub filep{
my($sname, $optype) = @_;
my $error_count;
if (!(-e $sname)){
print "$sname does not exist\n";
$error_count++;
}elsif(!(-s _)){
print "$sname has no size\n";
$error_count++;
}elsif(!(-r _)){
print "You lack read permmission for $sname\n";
$error_count++;
}
if($optype == 1){
if(!(-w _)){
print "You lack write permission for $sname\n";
$error_count++;
}
}
if($error_count == 0){
1;
}else{
0;
}
}
Whenever I run this with a '-o' on the command line of the program the hook test
(above) don't seem to run correctly (ie. run the subroutine when I don't want to). I
would appreciate any help I can get.
PS: I included the complete source for easy debugging. Sorry about the size of this
message.
__________________________________________________________________
The NEW Netscape 7.0 browser is now available. Upgrade now!
http://channels.netscape.com/ns/browsers/download.jsp
Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]