gyre007 has asked for the wisdom of the Perl Monks concerning the following question:

H I'm writing a simple text comparing tool. I read two command lines parameters passd to the scipts - 2 input files...however the script exits with the error messages that the second one does not exist...but it does! Even when I swap the order of those 2 given input file names still the first one gets opened but always the second one does not no matter what file I pass as a second argument... do you have any idea ?? Thanks The function in which it fails:
sub Init { my $file1; my $file2; my $tmp; if(defined($opt_h)){ print Syntax(); exit; } $file1 = $ARGV[0]; $file2 = $ARGV[1]; print "\nFirst file - $file1\nSecond File - $file2\n"; if((!defined($file1)) || (!defined($file2))){ print "\nSpecify the correct number of output files!\n"; print Syntax(); exit; } if(!defined($opt_c)){ print "\nNo config file provided, defualt configuration will be us +ed!\n"; init_default_config(); } else { read_config_file(); } if((!(-e $file1)) || (!(-e $file2))){ print "\nEither of specified files does not exist!\n"; exit; }else{ #opening input files for reading open FILE1, $file1 or die "\nCan't open $file1 for reading: $!\n"; open FILE2, $file2 or die "\nCan't open $file2 for reading: $!\n"; } #opening output files for writing open OUTFILE, "results" or die "\nCan't open $file2 for reading: $!\ +n"; #print the compare header to output file print OUTFILE "CALL-ID\n"; $tmp = "_" x 78; print OUTFILE "$tmp\n"; }

Replies are listed 'Best First'.
Re: Can't open SECOND input file given as script parameter ?
by JavaFan (Canon) on Oct 03, 2008 at 09:22 UTC
    You have:
    open OUTFILE, "results" or die "\nCan't open $file2 for reading: $!\n" +;
    Are you sure your code isn't failing here? That is, it cannot open the file 'results' and claims it cannot open $file2?

    Note also that you open this file for reading, not writing (and you try to print to it, so you need it open for writing).

      Yes ...YOU ARE ABSOLUTELY RIGHT! Thanks, that was the problem :(... Again thanks!

        ++

        Cut'n'paste claimed another victim... :)

        Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."